DEV Community

Cover image for 10 Important JavaScript Concepts for Interview
Shamanta Sristy
Shamanta Sristy

Posted on

10 Important JavaScript Concepts for Interview

Truthy and Falsy values

By default, javascript considers some values as true and the others false. Almost all values other than 0 and ''(empty string) are considered true in Javascript.
Some specific cases are there when Javascript will show true or false. Now we will discuss them.

True values:

'', '0', {} , [] All these will give true value

False values:

false, undefined, null , 0, NaN

Null vs Undefined

Null is a value that was defined but empty or null, whereas undefined is a value that was declared but no value assigned.
Undefined is a type where null is an object.

Double Equal ( == ) vs Triple equal ( === )

Double equals just check values and while triple equals check values with the type of the values. Double equals convert the type of the value and then check the value.

Scope

Scope means the accessibility of variables. Javascript has two types of scope: Local scope and Global scope.

Variables declared within a function are the local scope and these variables are accessible within only that function.

A global scope is a variable declared outside of a function and accessible from any function, scripts, and webpage,

Block scope

A block scope in Javascript is the area within any loop or condition like for, while, if, switch etc. To make it more clear, any javascript code within curly braces {} are block. ES6 made things easy for developers. let and const keywords are used in specific cases to declare variables that are accessible only within the block.

Closuer

Closure in javascript is when there's a function declared within a function. Or a function returns a function. The second function which is declared within the first one has variables that are not accessible from the parent function or first function (private variable). But the children function can access the value of the parent function.

Bind

The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

Call

Call returns function where parameters are separated by a comma.

function.call(firstParam, secondParam, thirdParam);
Enter fullscreen mode Exit fullscreen mode

Apply

Apply returns an array

function.apply(1st param, [secParam, thirdParam]);
Enter fullscreen mode Exit fullscreen mode

Window

The window object is supported by all browsers. It represents the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object.
Global functions are methods of the window object.

Top comments (1)

Collapse
 
gitgud5 profile image
gitgud5

Closure*