Most Common JavaScript JOB Interview Questions

I am going to share some Entry and Mid-level JavaScript developer job interview questions that you should know before JavaScript Interview.

I am going to discuss — What is Truthy and Falsy values, Tell me Null Vs Undefined, Double equal (==) vs triple equal (===), What is Implicit conversion, Discuss (Scope, block scope), What is acc/accumulator, What is Closure, What is Encapsulation, Tell the difference between bind-call and apply, this keyword, What is Asynchronous Javascript and describe setTimeout and setInterval, What is Event loop- stack and queue, What is Recursive function, What is Event bubble, Describe the key features of javascript, How recursion works and recursion vs iterative, What is DOM, What is a javascript callback function and how its work, Purpose of API, What is GET andPOST.
Take a deep breath and continue….

What are Truthy and Falsy values?

Truthy and Falsy values are the non-boolean values that are occurred or result to true or false when performing certain operations.
If you are writing an if condition for checking
Truthy and Falsy , you don’t need to check if something is empty or undefined or null. It will automatically be considered as false based on the following 7 predefined falsy values, they are:

  • the number 0
  • the BigInt 0n
  • the keyword null
  • the keyword undefined
  • the boolean false
  • the number NaN
  • the empty string "" (equivalent to '' or ``)
Exampleconst value = "";
// this condition is enough and no need to check value == ""
if(value) {
console.log(value); // This code will not be executed
}

const nullValue = null;
// this condition is enough and no need to check value === null
if(nullValue) {
console.log(nullValue); // This code will not be executed
}
Boolean(NaN) // false
Boolean([]) // true
Boolean({}) // true
//By fliping you can set true or false alsolet number1;
console.log(!!number1); // false

const number2 = 10;
console.log(!!number2); // true

const name1 = 'Tim';
console.log(!!name1); // true

Tell me Null Vs Undefined

At first glance, null and undefined may seem the same, but they are far from it.

Null is an empty or non-existent value & it must be assigned.
Undefined most typically means a variable has been declared, but not defined.

Example (Null):
const x= null;
console.log(x); // null
Example (Undefined):
const y= undefined;
console.log(c); // undefined

Double equal (==) vs triple equal (===)

Double Equals ( == ) checks for value equality only. Before checking the values, it (double equals) converts the types of the variables to match each other.
On the other hand,
Triple Equals ( === ) does not perform type coercion.

Example:
const number = 1234
const stringNumber = '1234'

console.log(number == stringNumber) //true
console.log(number === stringNumber) //false

What is Implicit conversion?

There are various operator and functions in JavaScript which automatically converts a value to the right type while operation like subtraction, multiplication, modules, etc. . But various operator creates a problem like ‘+’ operator.
All arithmetic operators do implicit conversion without an addition operator.

Example:
Input: "5" + "3"
Output: "53"
here + operator stands for string concatenation in this case.
But "5" - "1" gives output 4 by using Implicit Conversion.

Discuss Variable (Global Scope, Block/local scope)

Scope determines the accessibility of variables to JavaScript. The two types of scope are local and global:

Global variables are those declared outside of a block

Local variables are those declared insides of a block

Javascript variables can be reassigned. Using the local scope, we can actually create new variables with the same name as a variable in an outer scope without changing or reassigning the original value.

ExampleInput:
// Initialize a global variable
var species = "human";
function transform() {
// Initialize a local, function-scoped variable
var species = "werewolf";
console.log(species);
}
// Log the global and local variable
console.log(species);
transform();
console.log(species);
Output:
human
werewolf
human

What is acc/accumulator?

The accumulator accumulates/stores callback functions return values. It is the accumulated value previously returned in the last invocation of the callback — or initialValue, if it was supplied (see below).
It is basically used in the array reduce() method. The
reduce() the method executes a reducer function (that you provide) on each element of the array. For more

Example:
var numbers = [175, 50, 25];
console.log(numbers.reduce(myFunc));function myFunc(total, num) {
return total - num;
}

What is Closure?

A closure is a combination of a function bundled together (enclosed) with references to its surrounding state. In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.

What is Encapsulation?

Encapsulation in JavaScript is a process of wrapping code and data together into a single unit, for example, a capsule that is mixed of several medicines. We can create a fully encapsulated class in JavaScript by making all the data members of the class private. …

Why JavaScript is Single-threaded?

JavaScript is a single-threaded programming language which means only one thing can happen at a time. That is, the JavaScript engine can only process one statement at a time in a single thread.

What is asynchronous JavaScript?

What is event bubble?

What is HTTP Request?

HTTP works as a request-response protocol between a client and server. Example: A client (browser) sends an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.

--

--

MD. Rajibul Hasan | MERN Stack Developer

The Founder of Apps Maker BD and Frontend Developer at Penta Global Ltd.