What are the key features of JavaScript?

JavaScript is a high-level, interpreted, dynamically typed, or untyped programming language initially implemented within web browsers. It enables client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the web page’s Document Object Model (DOM). It is also referred to as the language of the browser.

JavaScript logo

JavaScript can be executed on the backend via JavaScript engines like NodeJS. JavaScript code can also communicate with databases and other APIs on the backend to retrieve data or send information.

Key features of JavaScript

  • Interpreted

JavaScript is considered an interpreted language, meaning that the JavaScript engine (interpreter) reads JavaScript statements one at a time and executes them immediately.

  • Dynamically typed or untyped

This means that you don’t need to specify the type of data that your variables can hold.

The code snippet below demonstrates dynamic typing in JavaScript.

let value = "Hello World" // String
console.log(value)
value = 3.14 // floating point number
console.log(value)
value = 10 // integer
console.log(value)
value = true // boolean
console.log(value)
  • First-class functions

First-class functions are functions that can be used like any other data type in the language. This means you can pass functions as arguments to other functions or return them from functions.

The code snippet below demonstrates first-class functions.

let value // declaring a variable
value = function () { // assingning a function to variable
console.log("Hello World");
}
console.log(value)
value(); // now, calling the function
  • Prototypal inheritance

Prototypal inheritance is a language feature that enables you to create objects using other objectsusually the prototype objects as templates. It eliminates the need for classes and allows for the easier inheritance of properties and methods to subclasses.

The code snippet below demonstrates prototypal inheritance.

var car = {
}
// assigns a property named wheel
// to 'car' using an object as a
// prototype
car.wheels = 4;
// creates a new object 'motorcycle',
// using an existing object as the prototype
var motorcycle = Object.create(car);
console.log(motorcycle.wheels);
// prints out 4 because because it inherits
// this property from `car` object
  • Closures

Closures is a programming concept in which any variable declared inside of a function can be accessed by any other nested function within the same scope.

function closure1() {
var x = 5
function addOne() {
console.log( x + 1 )
}
addOne() // prints 6
x = 10
addOne() // prints 11
}
closure1()
function closure2() {
console.log(typeof x) // x is private to closure1
}
closure2() // prints undefined

The features discussed above make JavaScript a very flexible programming language. This makes it very easy to begin to use without a steep learning curve.

Free Resources