10 Important Interview Question of Javascript

Habibur Rahman
3 min readMay 8, 2021

Truthy value and falsy value

Truthy values are values that evaluate to True in a boolean context. Falsy values are values that evaluate False in a boolean context.

Truthy value:

Without 0 any negative and positive numbers are truthy valuable. Anything in the string that includes white space is a truthy value even “0” is also a truthy value. Empty array and empty objects are also truthy values.

Falsy Value:

A statement can be false for many reasons such as if the value is 0, an empty string. If the value is undefined, null, Nan, and false on the other if the value is “false” it will be truthy.

Double equal vs Triple equal

123 == “123” (true)

This is a confusing thing in JavaScript. To compare normally we use double equal. Double equal just compare the value that’s why 123 == “123” (true). To avoid type correction we need to use triple equal Because triple not only checks the value it also checks the type.

Hoisting

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.

If you declare a variable using var it will be moved to the top of their scope before code execution and default value = undefine;

var LANGUAGE= “JAVA”;

var language =”JAVASCRIPT”;

function getL(){

if(!language){

var language= LANGUAGE

}

return language;

}

console.log(getL()); //JAVA

If you declare a variable using let it will be moved to the top of the block and this time default value will not set.

var LANGUAGE= “JAVA”;

var language =” JAVASCRIPT”;

function getL(){

if(!language){

let language= LANGUAGE

}

return language;

}

console.log(getL()); //JAVASCRIPT

Null vs Undefined

A value can be undefined for many reasons such as if a variable is declared but the value not set.

let p;

console.log(p) //undefine

If any function does not return;

function add(n,m){

let r=n+m;

}

console.log add(10,20)); //undefine

If any function consists of two or more parameters and when the function called one parameter is missing that time we get undefined.

function add(n,m){

let r=n+m;

console.log(m);

}

console.log add(10)); //undefine

Let’s consider we have an object named x ;

const x ={

name:”Habib”,

age:”23"

}

console.log(x.wife); // Unedefine

From the object, if we read a property that does not exist. we will get undefine.

One of the main differences between null and undefined is, we get undefine from code and null set in the code by the programmer.

call(),bind(),apply()

call(),bind(),apply() are javascripts method, to use an method belonging to another object.

Call:

var person = {

fullName: function() {

return this.firstName + “ “ + this.lastName;

}}

var person1 = { firstName:”John”, lastName: “Doe” }

var person2 = { firstName:”Mary”, lastName: “Doe” }

person.fullName.call(person1); // Will return “John Doe”;

Apply:

var person = {

fullName: function() {

return this.firstName + “ “ + this.lastName;

} }

var person1 = { firstName: “Mary”, lastName: “Doe” } person.fullName.apply(person1);

// Will return “Mary Doe”;

bind() and apply() are same, only deference is value passing. In bind() you can pass value normally but in apply() you need to pass value in an array.

ES6 includes new features:

  • The let keyword
  • The const keyword
  • JavaScript Arrow Functions
  • JavaScript For/of
  • JavaScript Classes
  • JavaScript Promises
  • JavaScript Symbol
  • Default Parameters
  • Function Rest Parameter
  • Array.find()
  • Array.findIndex()
  • New Math Methods
  • New Number Properties
  • New Number Methods
  • New Global Methods
  • JavaScript Modules

--

--