JavaScript interview questions

JavaScript interview questions and answers for beginners and professionals provides a list of top 100 JavaScript interview questions.

JavaScript interview questions

1) What is JavaScript?

JavaScript is the scripting programming language. It’s execute automatically as the page loads.It is object-based, lightweight and cross platform. it use to create interactive effects within web browsers.Currently many library and framework available for client side and server side.More Details

2) What is the use of JavaScript?

JavaScript use for client side (Angular, React etc) as well server side (Node). it use to create interactive effects within web browsers.

Main top 5 reason, why are you using JavaScript?

Reason 1:

JavaScript is very easy to learn for every developer. No setup is required, you can immediately start writing code and see the results fastly in your browser.

Reason 2:

JavaScript is used for both server, client side (Angular, React, Backbone, Vue) and server-side (Node), mobile, desktop, games, robotics and many more application.

Reason #3:
Server-side(Node) is most popular. There are over 35,000 NPM packages available!

Reason #4:
High-paying jobs for JavaScript developers.

Reason #5:
JavaScript is an incredibly expressive and most powerful language.

3) What is a “closure” in JavaScript?

A closure is the combination of a function and defined one function inside another parent function, and access to variables that are declared and defined in the parent function scope that is called closure.

For Example:

4) What is the output of typeof foo === “object”, if foo is an object?

5) What is the difference between var, const and let in JavaScript ?

JavaScript variables statement is used to declare a variable. In ES5, JavaScript used to be var keyword for assigning the variables. But in ES6, It identified, new keyword let and const. The basis usage of let and const are little difference to var keyword. More Details

  • var – Global Scope
  • const- block scope, immutable
  • let- block scope, mutable

var :- A JavaScript variable declared outside the function is global scope and inside the function local scope.But undeclared var keyword, inside the function variable will be global scope.

Undeclared var keyword as like :

const :- A variable which has a block level scope. It is immutable variable, In other word you can’t re-assign a value.

let :- A variable which has a block level scope. It is mutable variable, In other word you can re-assign a value.

let and var keyword example:

const keyword example:

6) What is the function callback in JavaScript ?

A callback function is a function passed into one function in another function as an parameter, It is a synchronous callback. As like below example :

7) What is a Promise and how Promises Work?

A promise is an object represents which can be returned synchronously from an asynchronous function. In other words eventual completion (or failure) of an asynchronous operation for result value.
The promise have three 3 possible states.
1. pending (not fulfilled or rejected)
2. fulfilled
3. rejected

You can create new promise object as like below:

Example:

8) What is the difference between call and apply javascript ?

Call Apply
1. Call Counts the number of arguments separated by Comma. 1. Apply uses Array as an Argument.
2. Call method accepts one or more arguments as objects and requires to be listed explicitly, means, it is a fixed number of arguments.
functionName.call(object1, “other argument”, “another one”);
2. Apply method requires an array as its second argument. This method is used if you don’t know the number of arguments to be passed or the arguments is already in an array.
functionName.apply(object2, [“argument1”, “argument2”, “argument3”]);

For example :

9) What is difference between this and $(this)?

this $(this)
1. It is the DOM object. 1. It is the jQuery wrapper around same.
2. When are you using this, you can call DOM methods on it. 2. But not jQuery methods.
2. But not DOM methods. 2. When are you using $(this), you can call jQuery methods.

10) What is a higher order functions ?

A higher order function is a function that may receive a function as parameter or even return a function that is called higher order functions.

11.) What are JavaScript Data Types?

There are different types of JavaScript Data Types.

  • Number
  • String
  • Boolean
  • Function
  • Object
  • Undefined

12.) What is the static keyword in JavaScript ?

The static keyword defines a static method for a class. Static methods are not called on instances of the class. Instead, they are called on the class itself. That is known as static keyword.

13.) What is yield keyword in JavaScript ?

The yield keyword is used to pause and resume a generator function. That is known as yield keyword.


Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of
Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.