0% found this document useful (0 votes)
4 views15 pages

2 JavaScript

The document outlines key JavaScript concepts and interview questions, focusing on ES6 features, data types, hoisting, scope, and functions. It covers advanced topics such as closures, promises, and the differences between client-side and server-side JavaScript. Additionally, it provides insights into best practices for coding and debugging in JavaScript, along with practical examples and explanations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

2 JavaScript

The document outlines key JavaScript concepts and interview questions, focusing on ES6 features, data types, hoisting, scope, and functions. It covers advanced topics such as closures, promises, and the differences between client-side and server-side JavaScript. Additionally, it provides insights into best practices for coding and debugging in JavaScript, along with practical examples and explanations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Source : JavaScript Interview Questions and Answers (2025) - InterviewBit

USE GFG , as it separates , experienced Q’s from non- Exp

Looks big, but it ain’t Because explained(So many pictures) not actually long , after 1-2 times
revision … It will be very brief , glide through explanations … 1-2 page worth of info !

R-1 : Done all


1 hr. Video Fine Write some Code from most asked(Shreyansh Coding) …. Some GPT ….

Latest Version: ES6 of JS Introduced Major features, written in


list :
1. Like python, need not to write Data types ….
2. Primitive:
 String () , Number, Boolean, BigInt (large integers ), Undefined, NULL, Symbol
 If it is a large Integer, then it will be automatically bigInt, instead of int
 Use typeOf(“abc”) -> Returns String …… Use typeOf() for knowing the name of data
structure
Non-primitive types
 Primitive data types can store only a single value. To store multiple and complex values.
 Object - Used to store collection of data.

3. In C++, primitive (or fundamental) data types are those directly built into the language, such
as: int (for integers), char (for characters), bool (for Boolean values), and float and double (for
floating-point numbers).
Arrays, on the other hand, are considered derived data types or compound types. They are
constructed from existing data types (primitive or other derived types) to store a collection.

4. Hoisting
Variable initializations are not hoisted, only variable declarations are
hoisted.
To Avoid hoisting, you can run JavaScript in strict mode by using “use strict” on top
of the code:

function a() or var x, keep Any place, they are hoisted but initialization is not hoisted !
Top to bottom only code but function and var are shifted upwards
Learn JavaScript Hoisting In 5 Minutes

5. “ == “ and “ === “ -> used to compare both values and types

6. Diff. b/w ‘var’ and ‘let’ keyword


 Var (Function) vs let (Block Scope):
Var, put inside any for loop or if – statement, it will work inside the whole function!

 Var(default initialization: Undefined) vs let (TDZ -> Temporal Dead


Zone )

 Initialization is not hoisted, but ‘var’ has a Scope, so hoisted to top!


 In let, hoisting doesn’t work in Declaration and For Initialization, it works for none of the two!

7. Coercion:
 String coercion:
‘ +‘ operator when used to add two numbers, outputs a number. The same ‘+’ operator when
used to add two strings, outputs the concatenated string.

Coercion also takes place when using the ‘-‘ operator, but the difference while using ‘–‘
operator is that, a string is converted to a number and then subtraction takes place.

> Boolean Coercion:

All values except false, 0, 0n, -0, “”, null, undefined, and NaN are truthy values.

Truthy values are those which will be converted (coerced) to true. Falsy values are those which will be
converted to false.
All values except false, 0, 0n, -0, “”, null, undefined, and NaN are truthy values.

 Logical operators:
OR (| |) operator - If the first value is truthy, then the first value is returned. Otherwise, always
the second value gets returned.
AND (&&) operator - If both the values are truthy, always the second value is returned. If the
first value is falsy then the first value is returned or if the second value is falsy then the
second value is returned. (Whatever false is Returned )

The ‘==’ operator, converts both the operands to the same type and then compares them.

var a = 12; var b = "12";

a == b // Returns true because both 'a' and 'b' are converted to the same type and then compared. Hence the
operands are equal

8. Java Script Dynamic type, no need to mention the Data Type and Change Data type,
when reassigned with another Value

9.

10. Pass by value vs Pass by Reference:

non-primitive data types are always passed by reference.


To Pass it as Reference Pointer we use, var x=#address

(Below Image) Just a Simple Example of how pass by Reference Works Especially for Objects/Non-
Primitive Data type:

(Below Image) Summary is Both are Pointing to the same location, so change in One, will lead to
change in second one!
11. Immediately Invoked Function (Acronym -> IIFE /IIFY) … Rush So skipped Explanation, for
11-14
Syntax of IIFE:
(function ()
{
// Do something;
} ) ();

No name, 1st set of Parenthesis (Avoid throw Error … As no name Function), 2nd set of
Parenthesis (command to Execute/To invoke) !

Self-Invoking Functions:
If a function expression is followed by (), it will execute automatically. No name for these kinds
of functions.

12. Strict mode in JavaScript and characteristics of JavaScript strict mode:

JS language is 'not particularly severe' when it comes to throwing errors. In 'Strict mode,'
however, all forms of errors, including silent errors, will be thrown. As a result, debugging becomes a
lot simpler
Characteristics: Disallows: duplicate parameters, reserved keywords as names, and Disallows
implicit global.

‘Reassignment’ column is something new!

13. Explain Higher Order Functions/ first-class citizens in JavaScript.


Functions that operate on other functions, either by taking them as arguments or by
returning them, are called higher-order functions.
YouLink

14. ‘this’ Keyword:


Normal Example Obj2 has function Called getName obj2 here has no function
named
So no Error! getadress so Error thrown !

15. call (), Apply (), bind ():


Later On! -> Slowing momentum, all done then these 20% Tough Q’s at Last with DSA ! … Search in
YT, Can’t Understand Once or Ask someone who knows JS!
Read 50% Easy, 1st as Difficult, Spoils mood So later, 1st build momentum

Akshay Saini channel, For YT Video

call (): If you need to do Function Borrowing, then use call method, just Passes the object, here
name2 in function called printFullName ()! …Remember the Syntax of how to call !

In general, also, if a Function used by 2 Objects, then call () will pass the current object and ‘this’
will refer to objects of the passed object
apply (): Other than 1st Parameter all others will be passed as array in 2nd parameter, will be passed
as an array [Needs more Clarification, see] …. Call and apply() -> are same kind of
functions .
bind(): returns the function in a variable, can be used later! (Mainly used in Function Currying) …
16. Exec () vs Test () -> both search “specific Pattern” in string [Not the whole string but
search the substring]
exec () -> Return the pattern directly; else, it'll return an 'empty' result.
test () -> Return the Boolean value 'true' on finding the given text otherwise, it will return 'false'.

…………………………………………………………………………………
… If need to understand, the whole working then read this
Photo
In General, test (): returns Boolean value, true or false … exec will automatically be reverse !
While exec (): returns pattern or empty string if no match

17. Currying: Currying is an advanced technique to transform a function of arguments n, to


n functions of one arguments.
Currying in JavaScript | JS Interview Questions
M-1: Bind () …. A.k.a. Partial Application → Fixes some args. now, leaves the rest for later. [In
JavaScript, currying often enables partial application, so partial application is synonymous
with Currying ]
-> preset the x to 2 or 3

Extreme Case: Initially Only pass 2 arguments, then 3 rd


one will not be Considered, If passed (See in Video Later)
M-2: Function Closure (Currying → Always breaks
into unary (1-arg) chain functions.)
‘X’ preset and then use it in the nested Function
Output: 6
This is actual Manual currying, where it is broken into unary functions of ‘n’ length chain.

18.
Advantages of External JavaScript
 Separation of concerns: HTML and JS kept in separate files, easing collaboration.
 Reusability & caching: One .js file can be shared across pages and cached by the browser.
 Maintainability: Cleaner, more readable codebase.

19.
Scope & Scope Chain in JavaScript
 Global vs. Local vs. Block:
o Global — accessible everywhere. (x=10 , will become global, if no var )

o Function — accessible only within that function.

o Block (let/const) — accessible only within {…}.

 Scope chain lookup: If a variable isn’t declared/Initialised and is used in the current (inner)
scope, JS searches outward through enclosing scopes, then global, before throwing a
ReferenceError.

20. Closures in JS: Closures are an ability of a function to remember the variables and functions that
are declared in its outer In General, we can say, scope of a Variable

Uses more memory, to store in heap

Closures Explained in 100 Seconds // Tricky Java333Script Interview Prep (Tricky Q’s also Explained see
@1:10 onwards )

21. Advantages of JS.


JavaScript is fast and easy to learn, runs both client- and server-side, adds rich interactivity
to web pages, and boasts a vast ecosystem of frameworks (Frontend many Frame.. and Backend –
[Link])
22. Object Prototype or Also called Class: (See this in more detail later)

 Date objects inherit properties from the Date prototype


 Math objects inherit properties from the Math prototype
 On top of the chain is [Link] Every prototype inherits properties(data members )
and methods from the [Link] / Class
 A prototype is a blueprint of an object. The prototype allows us to use properties and
methods on an object even if the properties and methods do not exist on the current object.

For E.g.: The JS engine sees that the method push does not exist on the current array object and
therefore, looks for the method push inside the Array prototype, and it finds the method.

23. Function callbacks: Learn JavaScript CALLBACKS in 7 minutes! 🤙 …..

1. 2.

1-> If ‘sum()’ took time and ‘displayConsole()’ was also called just below, then it would have been
executed!, So if You want to Avoid that then do function callback i.e. Once the function sum() is
executed then only displayConsole () will be executed !

2-> hello(leave) -> Correct hello(leave()) -> Incorrect, instantly, leave will be invoked !

24. Types of errors in JavaScript.

1. Syntax error: Syntax errors are mistakes or spelling problems in the code.
2. Logical error: Reasoning mistakes occur when the syntax is proper but the logic or program
is incorrect.

25. Memoization:

Advance JavaScript tutorial in Hindi #3 Memoization in JavaScript

Memoization: When Complex Calculation(memory and CPU use), then no need to Repeat the
same Calculations, Cache it and then give the same answer !
26. Recursion

Recursion, same as in Other, Programming language

E.g.

27. Use of Constructor Function in JS:

If we want to create multiple objects having similar


properties and methods, constructor functions are used.

28. DOM (Document Object Model): DOM is an object …. Read the Image

The JavaScript DOM explained in 5 minutes! 🌳 - YouTube …. Dom Manipulation Also


Explained

To a certain Degree! … Shown in Video, how through JS we can Access and do a lot
of Work which we initially did through HTML and CSS

JavaScript Interview - Q What is DOM What is the difference between HTML and
DOM?
1st of all You can configure the web page through JS now, as You have a DOM
Actually what allows manipulation is DOM, where in the DOM Tree, nodes are
updated or deleted, as new changes happen and you see the Change.

HTML is just markup language, but changes happen in DOM, and due to which
Website is Updated

29. The charAt() function of the JavaScript string finds a char element at the
supplied index.

30. BOM (Browser Object Model): JavaScript BOM Introduction Tutorial in


Hindi / Urdu
You Can Configure all these,
without use of mouse, but
through BOM, where the window

The Browser Object Model (BOM)


refers to all the objects provided
by the browser to interact with
the browser window,
independent of the web page
content (unlike the DOM, which
represents the page structure).

31. Client-side vs. Server-side JavaScript:

 Client-side runs in the user’s browser. The core JS language plus built-in
browser objects (BOM and DOM) are delivered with HTML and executed at
page-load.
 Server-side runs on a remote server in response to HTTP requests. It processes
data, performs I/O or database work, then sends back HTML/CSS/JS (which may
include client-side scripts).

JavaScript Interview Questions for


Experienced
1. Arrow Functions (ES6+)
A) Function Expression Only:
o Cannot use the function keyword or declare as a function statement—
arrow functions are always expressions.
B) Concise Syntax & Implicit Return
o For a single expression, omit braces {} and the return keyword:

C) Optional Parentheses
o If there’s exactly one parameter, you can drop the parentheses:

D) Lexical this Binding in Arrow Functions:

What's happening here?

 regularFunc is a normal
function, so this refers to obj1
(the object calling the
function). So, it returns
[Link], which is 10.
 arrowFunc is an arrow
function. It does not bind this
to obj1. Instead, it looks at the
outer scope in which it was
defined — which is the global
scope (window in browsers, or
global in [Link]).
 If there's no value in the outer
scope, it returns undefined

2) Prototype Design Pattern:


The Prototype Design Pattern is used to create new objects by copying an
existing object (a prototype) instead of creating them from scratch. This helps in
creating objects faster and with preset default values.

Real-Life Example:

Imagine you're creating business objects in an app (like a new employee record).
Instead of manually setting defaults (e.g., country = "India", role = "Intern") every
time,
you create one prototype object with all defaults, and clone it whenever a new
employee is added
3) Already Explained in Pt. 13

4) Rest Vs. Spread:

Rest → packs values into an array (used in function definitions).

Spread → ‘unpacks values’ from an array/object (used in function calls and


clones/merges).

Rest:

Used in function declarations to accept variable


number of arguments.

Collects arguments into a single array.

Always placed at the end of the parameter list.

Spread:
Used in function calls, arrays, and objects to unpack values.

Spreads elements of an array or properties of an object. 2 Examples to Explain:

5. In JavaScript, how many different methods/ways can you


make(Declare/Construct) an object:
A) Object Literals:

B) Using new Object(): C) Using a Constructor Function:

D). Using [Link](): E) Using Class Syntax


(ES6+):

F). Using [Link]():

6. Promises in JS:

Purpose: Handle asynchronous operations more efficiently than callbacks, avoiding


"callback hell”.

“States” of a Promise: (Theory, not used in writing Code, but


understanding)

1. Pending – Initial state, operation not completed.


2. Fulfilled – Operation succeeded.
3. Rejected – Operation failed.
4. Settled – Either fulfilled or rejected.
Creation: Using new Promise((resolve, reject) => {...}).

 reject() – Called on failure.


 resolve() – Called on success.

Consumption:

 .then() – Handles success


(fulfilled)
 .catch() – Handles failure
(rejected)

7. How to Create a Class in JS?

8.. Generator Function:

They can be stopped midway and


then continue from where they had
stopped.
Generator functions are declared
with the function* keyword
instead of the
normal function keyword.
In the case of generator functions, when called, they do not execute the code, instead, they return
a generator object. The generator object consists of a method called next(), this method when
called, executes the code until the nearest yield statement, and returns the yield value.

9. Weak set:
In JavaScript, a Set is a collection of unique and ordered elements.
Just like Set, WeakSet is also a collection of unique and ordered elements with some key
differences:

 Weakset contains only objects and no other type.


 An object inside the weakset is referenced weakly. This means, that if the object inside the weakset does not have a reference, it will be garbage
collected.
 Unlike Set, WeakSet only has three methods, add(), delete() and has() .

10(Already done)

11.. Weak Map:


In Javascript, Map is used to store key-value pairs. The key-value pairs can be of both
primitive and non-primitive types.

Weak Map: is similar to Map with key differences:

 The keys and values in weak map should always be an object.


 If there are no references to the object, the object will be garbage
collected.

Throws an Error because there is no object, only primitive data type!

12.. Object/Array Destructuring?

Object Destructuring is a new way to extract individual elements from an object or an array.

JavaScript Interview Questions and Answers (2025) - InterviewBit [Very Simple, just read in
website itself]

You might also like