JavaScript interview Question Everyone know it

Today, I am discuss about some common JavaScript interview question .so, lets be start now.

Mahfuz Alam
4 min readMay 8, 2021

|Null vs Undefined

Question: What are the differences between null and undefined?

Undefined: Undefined means that variable has been declared but has not be assigned or set a value. then the value of the variable will be ‘undefined’.

Null: Null means empty or absent value which is used by programmers to indicate “no value”. null is a primitive value and you can assign null to any variable.

For Example:

|Double Equal (==) vs Triple Equal (===)

Question: What are the differences between ==and ===?

Double equal does not care about what type of variable. If we compare a number with a string, it will not consider the type of value, it will be always return true.

Triple Equal must be consider what a type of variable .If we compare a number with a string, it will consider the type of value . If the data type doesn’t matching , it will be return false .

For example:

|Scope

In general terms, the scope will let us know at a given part of code, what are the variables and functions that we can or cannot access.

here are three types of scopes in JavaScript:

  • Global Scope: Variables or functions declared in the globally, which means all the variables and functions having global scope can be accessed from anywhere inside the code. For Example:
  • Local or Function Scope: Any variables or functions declared inside a function have local/function scope, which means that all the variables and functions declared inside a function, can be accessed from within the function and not outside of it. For Example:
  • Block Scope: Block scope is related to the variables declared using let and const. Variables declared with var do not have block scope. Block scope tells us that any variable declared inside a block { }, can be accessed only inside that block and cannot be accessed outside of it. For Example:

|Recursion

Recursion is a technique that which can call a function itself repeatedly. It has two conditions stage. In the main stage, we will check the condition and call a function itself repeatedly . In the final stage, the function doesn’t call itself and ends the program.

When the input value is lower than 10 then it returns the input value. Otherwise, it calls it’s again with the less one by one number. After all, the result of recursion(20) is 60339831552000

|Window

When we used in browser, that is shown all are in the window. We use document objects to access all elements and this document is also a part of this window object. There are many functions in the window. They are to handle the window object in a browser.

|Closure

Question: What is Closure? Give an example.

Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope. It gives you access to an outer function’s scope from an inner function. But using the Closure method, we can access the parent function’s variable from children’s function.

For Example:

| Array objects

We can convert an array to a string using toString() method.

For Example:

|Callback

  • A callback is a plain JavaScript function passed to some method as an argument or option.
  • It is a function that is to be executed after another function has finished executing, hence the name ‘callback’.
  • In JavaScript, functions are objects, So functions can take functions as arguments, and can be returned by other functions.

|Implicit Conversion

If we multiply with a string consist of only digits, normally we can think that there will be an error. But it will return something. It is called an implicit conversion.

For Example:

--

--

Mahfuz Alam

I am an enthusiastic JavaScript developer with knowing some framework for the frontend and the backend.