Category Archives: Javascript

Higher Order Functions Javascript

In Javascript, functions can be assigned to variables in the same way that strings or arrays can. They can be passed into other functions as parameters or returned from them as well. A “higher-order function” is a function that accepts functions as parameters and/or returns a function.

Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.

Higher order functions are a result of functions being first-class citizens in javascript.

Dynamically Typed Language

A language is dynamically-typed if the type of a variable is checked during run-time. Common examples of dynamically-typed languages includes JavaScript, Objective-C, PHP, Python, Ruby, Lisp, and Tcl.

avaScript is a dynamically typed language. In a dynamically typed language, the type of a variable is checked during run-time in contrast to statically typed language, where the type of a variable is checked during compile-time.

Implicit Type Coercion Javascript

Implicit type coercion in javascript is automatic conversion of value from one data type to another. It takes place when the operands of an expression are of different data types.

String coercion

String coercion takes place while using the ‘ + ‘ operator. When a number is added to a string, the number type is always converted to the string type.

When JavaScript sees that the operands of the expression x + y are of different types ( one being a number type and the other being a string type ) , it converts the number type to the string type and then performs the operation. Since after conversion, both the variables are of string type, the ‘ + ‘ operator outputs the concatenated string “33” in the first example and “24Hello” in the second example.

Hoisting Javascript

Hoisting is a default behaviour of javascript where all the variable and function declarations are moved on top.

This means that irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.

Data Types Javascript

There are two types of data types

Primitive types

String – It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.

Number – It represents a number and can be written with or without decimals.

BigInt – This data type is used to store numbers which are above the limitation of the Number data type. It can store large integers and is represented by adding “n” to an integer literal.

Boolean – It represents a logical entity and can have only two values : true or false. Booleans are generally used for conditional testing.

Undefined – When a variable is declared but not assigned, it has the value of undefined and it’s type is also undefined.

Null – It represents a non-existent or a invalid value.

Symbol – It is a new data type introduced in the ES6 version of javascript. It is used to store an anonymous and unique value.

To know the type of a JavaScript variable, we can use the typeof operator.

typeof “PHPCodez” // Returns “string”
typeof 7.14 // Returns “number”
typeof true // Returns “boolean”

Non-primitive types

Primitive data types can store only a single value. To store multiple and complex values, non-primitive data types are used.

Object – Used to store collection of data.