Master Javascript Interview Asked Concepts
Master Javascript Interview Asked Concepts
Master Javascript Interview Asked Concepts
Concepts to Ace
Technical Interview
*Disclaimer*
consistency.
interview.
www.bosscoderacademy.com 2
EASY
Q.1
How do you detect primitive or non-
primitive value types in Javascript?
In JavaScript, values are generally categorized as either primitive or
non-primitive (also known as reference types). Primitive values
include:
FA Number: Represents numeric values.
ZA String: Represents textual data.
tA Boolean: Represents true or false.
A Undefined: Represents an uninitialized variable or absence of a
value.
¬A Null: Represents the intentional absence of any object value.
ÄA Symbol: Represents a unique identifier.
Non-primitive values are objects, which include arrays, functions,
and custom objects.
www.bosscoderacademy.com 3
EASY
Javascript
// Using the typeof operator:
Important note:
typeof null returns "object" even though it's a primitive value.
www.bosscoderacademy.com 4
EASY
Using the Object() constructor:
A This constructor creates a new object wrapper for a value.D
A If a value is primitive, it will be equal to its object-wrapped
version.D
A If a value is non-primitive, it won't be equal to its object-wrapped
version.
Javascript
www.bosscoderacademy.com 5
EASY
Q.2
Explain the key features introduced in
Javascript ES6
In ES6, JavaScript introduced these key features:
Ye Arrow Functionsc
M Concise syntax for anonymous functions with lexical scoping.
e Template Literalsc
M Enables multiline strings and variable inclusion for improved
readability.
²e Destructuring Assignmentc
M Simplifies extraction of values from arrays or objects.
Ùe Enhanced Object Literalsc
M Introduces shorthand notation for defining object methods and
dynamic property names.
öe Promisesc
M Streamlines asynchronous programming with a cleaner, structured
approach.
www.bosscoderacademy.com 6
EASY
Q.3
What are the differences between var,
const & let in JavaScript?
Attribute var let const
Scope Functional
Block scope Block scope
scope
Can be
Can be updated Cannot be
Update/
updated and
but cannot be re- updated or re-
Re-declaration re-declared declared within declared within
within the scope the scope the scope
Declaration
Can be declared Can be declared Cannot be
without without being without being declared without
Initialization initialized initialized being initialized
www.bosscoderacademy.com 7
MEDIUM
Q.4
What are arrow functions in
Javascript?
Arrow functions are a concise way to write anonymous function
expressions in JavaScript. They were introduced in ECMAScript 6
(ES6) and are especially useful for short, single-expression functions.
return a + b;
};
In this example, the arrow function add takes two parameters (a and
b) and returns their sum. The => syntax is used to define the function,
and the body of the function is enclosed in curly braces {}. If there's
only one expression in the function body, you can omit the curly
braces and the return keyword:
Javascript
return a + b;
};
www.bosscoderacademy.com 8
MEDIUM
Here is an example showing how both traditional function expression
and arrow function to illustrate the difference in handle the this
keyword.
Traditional Function Expression:
Javascript
// Define an object
let obj1 = {
value: 42,
valueOfThis: function() {
};
console.log(obj1.valueOfThis()); // Output: 42
www.bosscoderacademy.com 9
MEDIUM
Arrow Function:
Javascript
// Define another object
let obj2 = {
value: 84,
valueOfThis: () => {
};
In the arrow function within obj2, this does not refer to obj2. Instead,
it inherits its value from the parent scope, which is the global object
(window in a browser environment). Consequently,
obj2.valueOfThis() returns undefined or may even throw an
error, as this.value is not defined in the global scope.
www.bosscoderacademy.com 10
MEDIUM
Javascript
While myMessage appears declared after its use, it's hoisted to the
top of the scope, allowing its reference (but not its initial value) before
the actual declaration line.
Javascript
function sayHello() {
console.log("Hello, world!");
www.bosscoderacademy.com 11
MEDIUM
Even though sayHello is defined after its call, JavaScript acts as if it
were declared at the beginning of the scope, enabling its execution.
Example 3: Hoisting within Local Scopes
Javascript
function performTask() {
var result;
performTask();
Hoisting also occurs within local scopes, like functions. Here, result
is hoisted to the top of the performTask function, allowing its use
before its explicit declaration.
Key Points:
¼ Only declarations are hoisted, not initializations. The example with
console.log(x); demonstrates this, as x is declared but not
initialised before its use, resulting in undefined.À
¼ Strict mode enforces declaration: Using "use strict"; at the
beginning of your code prevents using variables before they're
declared, helping avoid potential hoisting-related issues.
www.bosscoderacademy.com 12
EASY
Q.6 What is Strict Mode in Javascript?
Strict Mode is a feature that allows you to place a program, or a
function, in a “strict” operating context. This way it prevents certain
actions from being taken and throws more exceptions. The literal
expression "use strict"instructs the browser to use the javascript
code in the Strict mode.
function strict_function() {
'use strict';
x = 'Test message';
console.log(x);
www.bosscoderacademy.com 13
EASY
Q.7 What is NaN?
The NaN property in JavaScript represents a value that is "Not-a-
Number," indicating an illegal or undefined numeric value. When
checking the type of NaN using the typeof operator, it returns
"Number."
www.bosscoderacademy.com 14
EASY
Q.8
Is javascript a statically typed or a
dynamically typed language?
JavaScript is a dynamically typed language. In a dynamically typed
language, variable types are determined at runtime, allowing a
variable to hold values of any type without explicit type declarations.
This flexibility can make coding more convenient but may also lead to
runtime errors if types are not handled appropriately.
www.bosscoderacademy.com 15
MEDIUM
Q.9 What is NaN?
. Functions that treat other functions as values, either by:
DC Taking one or more functions as arguments8
0C Returning a function as a result
Common Examples of Built-in HOFs:
ba map():
Applies a function to each element of an array and creates a new
array with the results.8
Example:
const numbers = [1, 2, 3, 4, 5];
const doubledNumbers = numbers.map(number => number * 2); //
[2, 4, 6, 8, 10]
¡a filter():
Creates a new array containing only elements that pass a test
implemented by a provided function.8
Example:
const numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter(number => number % 2 ===
0); // [2, 4]
www.bosscoderacademy.com 16
MEDIUM
reduce():
. Applies a function against an accumulator and each element in an
array (from left to right) to reduce it to a single value.A
. Example:
const numbers = [1, 2, 3, 4];
const sum = numbers.reduce((accumulator, number) =>
accumulator + number, 0); // 10
Creating Custom HOFs:
You can define your own HOFs to encapsulate common patterns and
operations:
Javascript
function createMultiplier(factor) {
www.bosscoderacademy.com 17
EASY
Q.10
What is difference between Null and
Undefined
Feature Null Undefined
www.bosscoderacademy.com 18
MEDIUM
Q.11 What is DOM?
www.bosscoderacademy.com 19
MEDIUM
Q.12 What is BOM?
www.bosscoderacademy.com 20
MEDIUM
Explain about this keyword in
Q.13
Javascript with an example.
In JavaScript, the this keyword is a special variable that is
automatically defined in the scope of every function. Its value
depends on how the function is invoked. The this keyword is used to
refer to the object that is the current context of the function or, more
simply, the object that the function is a method of.
Here are some common scenarios that affect the value of this:
Global Context:
When this is used outside of any function or method, it refers to the
global object (in a browser environment, it usually refers to window).
Javascript
Method Invocation:
When a function is a method of an object, this refers to that object.
www.bosscoderacademy.com 21
MEDIUM
Javascript
const myObject = {
myMethod: function() {
};
myObject.myMethod();
Constructor Function:
When a function is used as a constructor with the new keyword, this
refers to the newly created instance of the object.
Javascript
function MyClass() {
www.bosscoderacademy.com 22
MEDIUM
Q.14 What is scope in Javascript?
There are two main types of scope in JavaScript: global scope and
local scope.
Global Scope:
W Variables declared outside of any function or block have global
scope.c
W Global variables are accessible throughout the entire code,
including within functions.
Javascript
var globalVar = "I am global";
function exampleFunction() {
exampleFunction();
www.bosscoderacademy.com 23
MEDIUM
Local Scope:
Variables declared inside a function or block have local scope.+
Local variables are only accessible within the function or block
where they are declared.
Javascript
function exampleFunction() {
exampleFunction();
Scope Chain:
The scope chain refers to the hierarchy of scopes in a program. When
a variable or function is referenced, JavaScript looks for it in the
current scope and then traverses up the scope chain until it finds the
variable or reaches the global scope.
www.bosscoderacademy.com 24
MEDIUM
Javascript
function mainFunction(){
innerFunction1();
innerFunction2();
mainFunction();
www.bosscoderacademy.com 25
MEDIUM
Q.15 What is closure in Javascript?
www.bosscoderacademy.com 26
MEDIUM
Javascript
function outerFunction() {
function innerFunction() {
let innerVariable = 5;
return innerFunction;
closureFunction();
www.bosscoderacademy.com 27
MEDIUM
outerFunction defines an outer variable (outerVariable) and an
inner function (innerFunction).
www.bosscoderacademy.com 28
HARD
Q.16
Explain call(), apply() and bind()
methods in Javascript.
In JavaScript, the call, apply, and bind methods are used to
manipulate how a function is invoked and set the value of this within
the function.
call method:
The call method is used to invoke a function with a specified this
value and arguments provided individually.
Javascript
function sayHello(greeting) {
www.bosscoderacademy.com 29
HARD
apply method:
The apply method is similar to call, but it accepts arguments as an
array.
Javascript
function sayHello(greeting) {
www.bosscoderacademy.com 30
HARD
Javascript
function sayHello(greeting) {
These methods are especially useful when dealing with functions that
are part of objects or classes, and you want to explicitly set the
context (this) for their execution.
www.bosscoderacademy.com 31
MEDIUM
Q.17
Explain call(), apply() and bind()
methods in Javascript.
In JavaScript, the call, apply, and bind methods are used to
manipulate how a function is invoked and set the value of this within
the function.
call method:
The call method is used to invoke a function with a specified this
value and arguments provided individually.
Javascript
function sayHello(greeting) {
www.bosscoderacademy.com 32
MEDIUM
In this example, the add function is pure because it only depends on
its input parameters (a and b) to produce a result and doesn't modify
any external state.
Contrast this with an impure function that relies on external state or
has side effects:
Javascript
// Impure function (has side effects)
let total = 0;
function addToTotal(value) {
total += value;
addToTotal(5);
console.log(total); // Output: 5
www.bosscoderacademy.com 33
MEDIUM
Q.18 What are prototypes in Javascript?
this.name = name;
Person.prototype.greet = function() {
};
www.bosscoderacademy.com 34
MEDIUM
Javascript
www.bosscoderacademy.com 35
HARD
Q.19
What are callback functions in
Javascript and what is callback hell?
In JavaScript, a callback is a function that is passed as an argument
to another function and is executed after the completion of some
asynchronous operation or at a specified time. Callbacks are
commonly used in scenarios like handling asynchronous tasks, event
handling, and other situations where the order of execution is not
guaranteed.
Javascript
function customGreeting(name) {
function outerFunction(callback) {
callback(name);
outerFunction(customGreeting);
www.bosscoderacademy.com 36
HARD
Callback hell (or "pyramid of doom") is a situation in which multiple
nested callbacks make the code difficult to read and maintain. This
often occurs when dealing with asynchronous operations, such as
making multiple API calls or handling multiple events.
Javascript
getUser(function(user) {
getProfile(user.id, function(profile) {
getPosts(user.id, function(posts) {
});
});
});
});
www.bosscoderacademy.com 37
MEDIUM
Q.20
What is Temporal Dead Zone in
Javascript?
The Temporal Dead Zone is a phenomenon in JavaScript associated
with the use of the let and const keywords, unlike the var keyword. In
ECMAScript 6, attempting to access a let or const variable before it is
declared within its scope results in a ReferenceError. The term
"temporal dead zone" refers to the timeframe during which this
occurs, spanning from the creation of the variable's binding to its
actual declaration.
function exampleMethod() {
var value1 = 1;
let value2 = 2;
www.bosscoderacademy.com 38
HARD
Q.21 What are promises in Javascript?
});
It's important to note that the rest parameter must be the last
parameter in the function declaration. For example, this is valid:
www.bosscoderacademy.com 40
MEDIUM
Javascript
// code here
Javascript
// code here
www.bosscoderacademy.com 41
HARD
Q.23
What are generator functions in
Javascript?
In JavaScript, generator functions are a special kind of function that
allows you to control the execution flow and pause/resume it at
certain points. Generator functions are defined using the function*
syntax and use the yield keyword to produce a sequence of values.
When a generator function is called, it returns an iterator called a
generator.
function* simpleGenerator() {
yield 1;
yield 2;
yield 3;
} // Creating a generator
www.bosscoderacademy.com 42
HARD
console.log(generator.next()); // { value: undefined,
done: true }
In this example:
D The function* simpleGenerator() syntax defines a generator
function.Q
D The yield keyword is used to produce values. Each time yield is
encountered, the generator pauses its execution, and the yielded
value is returned to the caller along with done: false. The
generator can be resumed later.Q
D The generator.next() method is used to advance the
generator's execution. It returns an object with two properties:
value (the yielded value) and done (a boolean indicating whether
the generator has finished).
www.bosscoderacademy.com 43
MEDIUM
Q.24 What is the difference between function
declarations and function expressions?
Function Declaration:
C A function declaration is a statement that defines a function and
hoists it to the top of the current scope.N
C It starts with the function keyword, followed by the function
name, parameters (enclosed in parentheses), and the function
body.N
C Example:
Javascript
function add(a, b) {
return a + b;
www.bosscoderacademy.com 44
MEDIUM
Example:
Javascript
return a + b;
};
www.bosscoderacademy.com 45
HARD
What is the difference between setTimeout,
Q.25 setImmediate and process.nextTick?
}, 1000);
¦S setImmediate:
n Schedules the callback to be executed in the next iteration of the
event loop.j
n It's often used when you want the callback to be executed
immediately after the current event loop cycle.
www.bosscoderacademy.com 46
HARD
Javascript
setImmediate(() => {
});
H= process.nextTick:
\ Executes the callback after the current event loop cycle, but
before the event loop continues processing other I/O events.U
\ It is often used when you want to execute a callback after the
current operation but before I/O events.
Javascript
process.nextTick(() => {
});
www.bosscoderacademy.com 47
Why
Bosscoder?
750+ Alumni placed at Top
Product-based companies.
Explore More