Learn Javascript Interview Topics & Answer With Some Easy Description

In the javascript interview question, there are many important topics which are Null vs Undefined, Double Equal vs Triple Equals, Scope, Block Scope, function Scope, Global variable, Local variable, Closure, etc.

Now I am describing those topics with sort and easy description….

Null Vs Undefined

In javascript, Undefined means a variable has been declared but has not yet been assigned a value, such as

Example:

Null is an assignment value. It can be assigned to a variable as a representation of no value:

The Triple equals(===) Vs The Double equals(==)

The triple equals are strict equality operator, will compare both the value and type of the operands. If the value is the same but the datatype is not then the equality will evaluate to false.

Example:

The Double equals are checking the equal side value firstly. If the values are equal then it compares the datatype and tries to convert the values in the same datatype.

Example:

Scope

Scope determines the visibility or accessibility of a variable or other resource in the area of your code.

Javascript variables have only two scopes....

A global variable has a global scope which means it can be defined anywhere in your javascript code.

A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

Function Scope:

Whenever you declare a variable in a function, the variable is visible only within the function. you can’t access it outside the function. “var” is the keyword to define a variable for function-scope accessibility.

Example:

Block Scope:

Block scope is the area within if, switch conditions or for and while loops. Generally speaking, whenever you see {curly brackets}, it is a block. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.

Example:

Closure

Calling or returning a function from within one of the functions will create a close environment. then if the function inside has access to a variable outside its environment, then the function will have a value of its own. Whenever a function is called with a separate variable, it will create its own environment. This is called Closure.

Example:

I am a front End web developer.