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 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.
JavaScript is considered an interpreted language, meaning that the JavaScript engine (interpreter) reads JavaScript statements one at a time and executes them immediately.
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" // Stringconsole.log(value)value = 3.14 // floating point numberconsole.log(value)value = 10 // integerconsole.log(value)value = true // booleanconsole.log(value)
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 variablevalue = function () { // assingning a function to variableconsole.log("Hello World");}console.log(value)value(); // now, calling the function
Prototypal inheritance is a language feature that enables you to create objects using
The code snippet below demonstrates prototypal inheritance.
var car = {}// assigns a property named wheel// to 'car' using an object as a// prototypecar.wheels = 4;// creates a new object 'motorcycle',// using an existing object as the prototypevar motorcycle = Object.create(car);console.log(motorcycle.wheels);// prints out 4 because because it inherits// this property from `car` object
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 = 5function addOne() {console.log( x + 1 )}addOne() // prints 6x = 10addOne() // 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.