Top 10 Javascript interview questions : Concepts every javascript developer should know
interview questions , Javascript / 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…

Understanding ‘this’ in Javascript
interview questions , Javascript / March 20, 2018

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)

In the above example, a function WrapAll() is being called from the global scope. The global scope means in the context of window object this and ‘use strict’

Here this is undefined as use strict prevent global object   Now we can see how the this keyword works in an objects point of view by creating a new object.To create an object,we need a constructor function

Callback functions In the above object we use fetch which returns a promise.To the promise .then we give a call back function  as seen below

Here , we can see that the console.log inside the callback function gives the window object.This is because the callback function is a normal function in Javascript which is put in to the callstack by the event loop from the event queue.   To get the ‘this’ inside the callback we can use bind()

We can also use…

Fat arrow functions or arrow functions in Javascript
interview questions , Javascript / February 20, 2018

Arrow Functions primarly have two big advantages 1 They let us provide a shorter way to define functions 2  Arrow functions does not have their own  this, arguments(JavaScript functions have a built-in object called the arguments object), super, or 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. 1 They let us provide a shorter way to define functions Arrow functions provide us with a shorter way to defined function.For example see the following function which is written using the normal syntax

  The console.log gives output 6 . Now check the same function using arrow syntax

Now we can see a function with  a few parameters

Using arrow syntax

  2 Arrow functions – this,callbacks and bind() To understand more on this keyword read the following link See the following example.this is not available inside the callback function

To make this available inside the callback function…

Share this page in social media platforms