Top 10 Conceptual Question for Your Next Interview

Abdul Hasib Ovi
4 min readMay 8, 2021

Let’s hunt the interview together…

Truthy and Falsy Value

If we want to make a decision we ask our mind a question and then based on the answer we decide what to do. Let’s think about a scenario, Your mother asked you if you have eaten your lunch. The answer could be yes or no. If yes your mother will not give you food again and if the answer is no your mother will provide you lunch. Can you see here a condition is happening? Truthy and Falsy values are important for conditional rendering. As falsy values are limited we will talk about this first.

Some Falsy values:

  1. 0
  2. false //boolean
  3. “” //empty string
  4. null
  5. undefined
  6. NaN

The rest are Truthy values. Empty arrays and empty objects are also truthy values.

Null and Undefined

These two are primitive data types. Both are falsy values. Null represents an empty variable that is done intentionally empty. And undefined represents any unintentional empty variable. If we declare a variable and do not assign its value. We will get undefined.

Example,

let a;
console.log(a) // undefined

You can also set the value of a variable as null or undefined,

let a=null;
console.log(a) // null
let a=undefined;
console.log(a) // undefined

Double Equal(==) vs Triple Equal(===)

Single equal is called assign operator as it is used to assign value to a variable. Ans double and triple equal are called comparison operators. Though both are comparison operators there’s some basic difference we should know.

Double equal mainly does automatic type conversion so we can say it, flexible comparison operator. If you compare number 2 with string “2” double equal comparison will return true.

let a = 2;
let b = "2"
a==b // true
let a = 1;
let b = true;
a==b //true

Triple equal compares two variables in strict mode mainly. It compares both the values and types. So to return true both variables should be the same value and same type.

let a = 2;
let b = "2"
a==b // falselet a = 1;
let b = true;
a===b // false

Function Scope

Scope defines an area of accessibility of variables. JavaScript has function scope. Each function creates a new scope. This means a variable is accessible from any place of a function. But it cannot be accessed from outside of the function. But it can be accessed from outer if-else or other curly braces block

function add(){
var a = 2;
var b = 3;
return a+b;
}console.log(a) // reference error;if(true){
var a = 2;
var b = 3;
}console.log(a) // 2

Block Scope

A block scope is the area within if, switch conditions or for and while loops. Generally speaking, whenever you see {curly brackets}, it is a block. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.

if(true){
let a = 2;
let b = 3;
}console.log(a) // reference error

Access Outer Scope Variable

Child function can access the variable from parent function. This is done by the closure. Closure means a memory where the variables used in child function from outer function is stored temporarily.

function outer(){
var a = 3;
function inner(){
console.log(a) // 3
}
}

Bind Method

The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

const bindFn= newFn.bind(mainFn);
console.log(bindFn()); // will get the result from mainFn

Call Method

The call() method calls a function with a given this value and arguments provided individually.

newFn.call(mainFn); // will get the result from mainFn

If we have to pass parameters we just use comma. Here’s an example with 3 parameters.

newFn.call(mainFn, p1, p2, p3); // will get the result from mainFn

Apply Method

The apply() method calls a function with a given this value, and arguments provided as an array (or an array-like object).

newFn.apply(mainFn); // will get the result from mainFn

If we have to pass parameters we just use array of parameters. Here’s an example with 3 parameters.

newFn.call(mainFn, [p1, p2, p3]); // will get the result from mainFn

Window

The window object is supported by all browsers. It represents the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object.Global variables are properties of the window object. Global functions are methods of the window object.

Even the document object (of the HTML DOM) is a property of the window object:

window.document.getElementById("header");

is the same as:

document.getElementById(“header”);

--

--