TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses ยท 55.7K subscribers
Post #3604 1.96K
๐Ÿš€ JavaScript Interview Questions with Answers โ€” Part 2

11. What is the typeof operator?

The typeof operator is used to determine the data type of a value.

Example:

console.log(typeof "Hello");   // "string"
console.log(typeof 100); // "number"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"


Important Interview Point:

console.log(typeof null);


Output: "object"

This is a historical behavior in JavaScript.

12. What are template literals?

Template literals are strings created using backticks ``.

They allow you to easily embed variables and expressions using ${}.

Example:

const name = "Ajay";
const age = 25;

console.log(`My name is ${name} and I am ${age} years old.`);


Output: My name is Ajay and I am 25 years old.

Benefits:

Easy string interpolation

Supports multi-line strings

Allows expressions inside strings

13. What are JavaScript operators?

Operators are symbols used to perform operations on values.

Common Types:

Arithmetic: + - * / % **

Comparison: == === != !== > < >= <=

Logical: && || !

Assignment: = += -= *= /=

Example:

const a = 10;
const b = 5;
console.log(a + b); // 15
console.log(a > b); // true


14. What is the ternary operator?

The ternary operator is a short way of writing an if...else statement.

Syntax:

condition ? valueIfTrue : valueIfFalse;


Example:

const age = 20;
const result = age >= 18 ? "Adult" : "Minor";
console.log(result);


Output: Adult

Equivalent if...else:

if (age >= 18) {
result = "Adult";
} else {
result = "Minor";
}


Interview Tip: Use ternary operators for simple conditions. Avoid deeply nested ternaries because they reduce readability.

15. What is variable hoisting?

Hoisting is JavaScript's behavior of processing declarations before executing the code in their scope.

With var:

console.log(x);
var x = 10;


Output: undefined

The declaration is hoisted, but the assignment happens later.

With let and const:

console.log(x);
let x = 10;


This results in a ReferenceError.

let and const are hoisted but remain in the Temporal Dead Zone (TDZ) until their declaration is reached.

Function declarations are also hoisted:

greet();
function greet() {
console.log("Hello");
}


16. What is scope in JavaScript?

Scope determines where a variable can be accessed in a program.

Example:

function test() {
let message = "Hello";
console.log(message);
}
test();


message is accessible inside the function but not outside it.

Main Types:

Global Scope

Function Scope

Block Scope

Module Scope

Understanding scope is essential for closures and avoiding variable conflicts.

17. What are global, function, and block scope?

Global Scope

A variable declared outside functions or blocks can generally be accessed throughout the script.

let name = "Deepak";
function greet() {
console.log(name);
}


Function Scope

Variables declared with var inside a function are accessible throughout that function.
  • โค 2
More from @javascript_courses
  1. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  2. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
  3. Oct 4, 2026DSA Handwritten Notes
  4. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these stโ€ฆ
  5. Sep 27, 202610 Websites Every Developer & AI Enthusiast Should Bookmark โœ… roadmap.sh โ€“ Step-by-step leโ€ฆ
  6. Sep 26, 2026๐Ÿ”น Escape Characters 2๏ธโƒฃ5๏ธโƒฃ New Line You can use \n and \t: const message1 = "Hello\nWorldโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’