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

๐Ÿง  1. What is JavaScript and what is it used for? 

JavaScript is a high-level, interpreted programming language mainly used to make websites interactive and dynamic. It runs inside the browser and can also run on servers using Node.js.

Common Uses of JavaScript: 
โ€ข Building interactive websites
โ€ข Form validation
โ€ข Animations and sliders
โ€ข API calls and dynamic content
โ€ข Web apps and mobile apps
โ€ข Backend development with Node.js
โ€ข Game development

Example: console.log("Hello World");

2. What are the data types in JavaScript? 

JavaScript has two categories of data types:

Primitive Data Types 
1. String
2. Number
3. Boolean
4. Undefined
5. Null
6. BigInt
7. Symbol

Reference Data Types 
1. Object
2. Array
3. Function

Example:
let name = "Deepak";      // String 
let age = 25;             // Number 
let isActive = true;      // Boolean 
let data = null;          // Null 
let value;                // Undefined 

3. What is the difference between null and undefined?

Feature | null | undefined 
Meaning | Intentional empty value | Variable not assigned 
Type | object | undefined 
Assigned by | Developer | JavaScript automatically 

Example:
let a = null; 
let b; 

console.log(a); // null 
console.log(b); // undefined 

Key Point: 
โ€ข null means โ€œempty intentionallyโ€
โ€ข undefined means โ€œvalue not assigned yetโ€

4. What is the difference between == and ===? 

== (Loose Equality) 
โ€ข Compares values only
โ€ข Performs type conversion (type coercion)

=== (Strict Equality) 
โ€ข Compares both value and data type
โ€ข No type conversion

Example:
console.log(5 == "5");   // true 
console.log(5 === "5");  // false 

Interview Tip: Always prefer === because it gives more predictable results.

5. What are primitive vs reference types? 

Primitive Types 
Stored directly in memory. 
Examples: String, Number, Boolean, Null, Undefined 

Reference Types 
Stored by reference (memory address). 
Examples: Objects, Arrays, Functions 

Example:
let a = 10; 
let b = a; 
b = 20; 
console.log(a); // 10 

Reference Example:
let obj1 = {name: "John"}; 
let obj2 = obj1; 
obj2.name = "Mike"; 
console.log(obj1.name); // Mike 

Key Difference: 
โ€ข Primitive โ†’ copied by value
โ€ข Reference โ†’ copied by reference

6. What is type coercion? 

Type coercion means JavaScript automatically converts one data type into another during operations or comparisons.

Example:
console.log("5" + 2); // "52" 
console.log("5" - 2); // 3 

Why? 
โ€ข + prefers string concatenation
โ€ข - converts strings to numbers

Types of Coercion: 
1. Implicit coercion (automatic)
2. Explicit coercion (manual)

Explicit Example: Number("10"); // 10 , String(123); // "123"

7. What is the difference between let, const, and var?

Feature | var | let | const 
Scope | Function | Block | Block 
Reassign | Yes | Yes | No 
Redeclare | Yes | No | No 
Hoisted | Yes | Yes | Yes 

Example:
var a = 10; 
let b = 20; 
const c = 30; 

Key Points: 
โ€ข Use let for changing values
โ€ข Use const for fixed values
โ€ข Avoid var in modern JavaScript

8. What is block-scope vs function-scope? 

Function Scope 
Accessible inside the entire function. var is function-scoped.

Block Scope 
Accessible only inside {} block. let and const are block-scoped.

Example:
function test() { 
    if (true) { 
        var a = 10; 
        let b = 20; 
    } 
    console.log(a); // Works 
    console.log(b); // Error 
}

9. What is the difference between let and var?

Feature | var | let 
Scope | Function | Block 
Redeclare | Allowed | Not allowed 
Hoisting | Yes | Yes (TDZ applies) 

Example:
var x = 10; 
var x = 20; // Allowed 

let y = 10; 
let y = 20; // Error

Important: let avoids many bugs caused by var.

10. How do you declare and use variables? 

Variables are used to store data.

Syntax:
let name = "Deepak"; 
const age = 25;

Rules:
- Use meaningful names 
- Cannot start with numbers 
- Case-sensitive 

Double Tap โค๏ธ For Part-2
  • โค 13
  • ๐Ÿ™ 1
  • ๐Ÿคฃ 1
  • ๐Ÿ˜ญ 1
  • ๐Ÿ—ฟ 1
More from @javascript_courses
  1. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  2. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  3. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
  4. Oct 4, 2026DSA Handwritten Notes
  5. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these stโ€ฆ
  6. Sep 27, 202610 Websites Every Developer & AI Enthusiast Should Bookmark โœ… roadmap.sh โ€“ Step-by-step leโ€ฆ
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 โ†’