Some important interview Question in JavaScript and ES6

Short Description

1. What is a callback function?

A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action. Let’s take a simple example of how to use callback function

2. Why do we need callbacks?

The callbacks are needed because JavaScript is an event driven language. That means instead of waiting for a response JavaScript will keep executing while listening for other events. Let’s take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.

As observed from the output, JavaScript didn’t wait for the response of the first function and the remaining code block got executed. So callbacks are used in a way to make sure that certain code doesn’t execute until the other code finishes execution.

3. What is a callback hell?

Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,

4. What is the typeof operator?

You can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.

5. What is undefined property?

The undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.

Any variable can be emptied by setting the value to undefined.

6. What is null value?

The value null represents the intentional absence of any object value. It is one of JavaScript’s primitive values. The type of null value is object. You can empty the variable by setting the value to null.

7. What is the difference between null and undefined?

Null

  1. It is an assignment value which indicates that the variable points to no object.
  2. Type of null is object.
  3. The null value is a primitive value that represents the null, empty, or non-existent reference.
  4. Indicates the absence of a value for a variable
  5. Converted to zero (0) while performing primitive operations

Undefined

  1. It is not an assignment value where a variable has been declared but has not yet been assigned a value.
  2. Type of undefined is undefined
  3. The undefined value is a primitive value used when a variable has not been assigned a value
  4. Indicates absence of variable itself
  5. Converted to NaN while performing primitive operations

8. What is isNaN?

The isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise, it returns false.

9. What are global variables?

Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable

10. What is NaN property?

The NaN property is a global property that represents “Not-a-Number” value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program, but it can be used as a return value for few cases

11. What is event bubbling?

Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM elemen.

12. What is BOM?

The Browser Object Model (BOM) allows JavaScript to “talk to” the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.

Browser Object Model (BOM)

--

--

I am Aiman. I am a web developer. I can learn anything at any time. For that, I take the help of Google. My core skill is based on JavaScript .

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahad Hossain Aiman

I am Aiman. I am a web developer. I can learn anything at any time. For that, I take the help of Google. My core skill is based on JavaScript .