Top 10 Javascript interview questions : Concepts every javascript developer should know

August 20, 2018

1  Explain let,var and const variable declaration and explain their scope .what is strict mode?

2  What are callbacks and callback hell in javascript . What are higher order functions?

3 What is  hositing in javascript ?

4 What are prototypes and explain Prototypal inhertiance ?

5 What are Closures in javascript?

6 What are arrow functions / fat arrow functions  in Javascript?

7 What doe this keyword indicate in javascript?

8 What are promises in JavaScript?

9 What is bubbling and propogation in Javascript?

10 What are generators in Javascript?

ANSWERS

1  The scope of var is the current execution context.That is, scope of var is global,if used outside a function and the scope is the function block if used inside the function. See more here  Understanding variable scope(let,var,const),hoisting in Javascript and Temporal Dead Zone(TDZ)

2  In  most programming languages , functions can accept other function(s) as arguments or return a function .Such functions are called Higher order functions.In JavaScript most APIs and Modules can accept function as an argument to a function .The functions are called  callbacks.see more here Understanding Callbacks and Callback hell in JavaScript : asynchronous behaviour of Javascript Part -1

3 To hoist means to pull or move up . Javascript hoisting means variable and function declarations are pulled to the top of the scope while compilation.What actually happens is that declarations are stored in memory.In the following example we will see how hoisting works .See more here  Understanding variable scope(let,var,const),hoisting in Javascript and Temporal Dead Zone(TDZ)

4  Nearly all objects in JavaScript are instances of Object which sits on the top of a prototype chain.The Object.prototype is on the top of the prototype inheritance chainThat means almost all the objects in JavaScript inherit the properties and methods from Object.prototype.JavaScript Date objects inherit from Date.prototype. Array objects inherit from Array.prototype.See more Prototypes and Prototypal inheritance in Javascript

5 A closure is the combination of a function and the lexical environment within which that function was declared. We will take a detailed look in to closures using the following examples.See more here Closures in JavaScript

6  Arrow functions does not have their own  thisarguments(JavaScript functions have a built-in object called the arguments object)super, or new.target. These functions cannot be used as constructors.Arrow functions does not have their own this and it will have this value from their enclosing context .We can use this from the surrounding scope inside an arrow function such that we need not use bind() to bind this to a callback function.This more shorter yet more efficient way of writing a function was introduced in ES6. See more here  Fat arrow functions or arrow functions in Javascript

This in Javascript refers to the object to which the function belongs. The value of this is determined by how a function is called.’This’ refers to the “owner” of the function.In the case of a normal function like below ‘this‘ refers to the global object (window object).See more here Understanding ‘this’ in Javascript

8 The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.Promises provide a better way for managing asynchronous operations when compared to traditional callback-based way.
Promises represent data that may not be available but will be available later upon completing some asynchronous operation.See more here Understanding Promises in JavaScript : asynchronous behaviour of Javascript Part -2

9 Event propagation is the propagation of an event through the elements in the HTML DOM.See more here Event propagation in javascript – Capturing and Bubbling

10 In ES6 version , a new kind of functions called generator functions were introduced.These special functions helps you to manage asynchronous operations with more ease .Generator functions can be paused and then continued.Generator functions are declared with an asterisk (*) and has an yield keyword which yields data.See more here Generator Functions in JavaScript : asynchronous behaviour of Javascript

 

3 Comments

  • nidhi jain September 5, 2018 at 4:51 am

    Thanks alot for your efforts really useful questions!!!

  • cialis March 28, 2019 at 6:32 pm

    Hey there just wanted to give you a quick heads up and let you know a few of the images aren’t loading properly.
    I’m not sure why but I think its a linking issue. I’ve
    tried it in two different web browsers and both show the same
    results.

  • lena baber May 16, 2019 at 7:57 pm

    Appreciate this post. Will try it out.

Leave a Reply

Your email address will not be published. Required fields are marked *