JavaScript is a high-level, interpreted programming language that powers interactivity on the web.
It runs in browsers and servers (Node.js), supports multiple paradigms (functional, OOP), and interacts with HTML/CSS to create dynamic interfaces.
Core traits:
- Interpreted, dynamically typed, single-threaded
- Event-driven, prototype-based
- Supports asynchronous programming
Common uses:
- Web interactivity (frontend)
- APIs and backend logic (Node.js)
- Cross-platform apps (React Native, Electron)
- 1995 – Created by Brendan Eich (Netscape)
- 1997 – ECMAScript standard introduced (ES1)
- 2009 (ES5) – Added
forEach,map, JSON support, strict mode - 2015 (ES6) – Introduced
let,const, classes, arrow functions, promises, modules - 2016–2025 – Yearly ECMAScript updates:
- Async/Await (ES2017)
- Optional chaining
?.(ES2020) - Nullish coalescing
??(ES2020) - Top-level await (ES2022)
- Records/Tuples (proposed ES2025)
Engine: Converts JS code → bytecode → machine instructions
Examples:
- Chrome: V8
- Firefox: SpiderMonkey
- Safari: JavaScriptCore
Event Loop:
- Manages asynchronous tasks via Call Stack, Web APIs, Callback Queue, and Microtask Queue.
- Ensures non-blocking execution.
- Install Node.js → nodejs.org
Verify withnode -v. - Editor: Use VS Code with ESLint + Prettier.
- Browser Console: Test snippets (Ctrl + Shift + J).
- Online Platforms: CodePen, JSFiddle, Replit.
Browser:
<script>
console.log("Running in browser");
</script>Node.js:
node app.js- Who created JavaScript and in what year?
- What is the purpose of the Event Loop?
- Name two differences between Node.js and browser JavaScript environments.
- What does ECMAScript refer to?
- Give two new features introduced in ES6.
| Keyword | Scope | Reassignment | Redeclaration | Hoisted |
|---|---|---|---|---|
var |
Function | ✅ | ✅ | Yes (undefined) |
let |
Block | ✅ | ❌ | No |
const |
Block | ❌ | ❌ | No |
Best practice:
- Use
constby default. - Use
letwhen reassignment is required. - Avoid
varfor modern code.
Primitive Types:
String, Number, Boolean, Null, Undefined, Symbol, BigInt
Reference Types:
Object, Array, Function
typeof "hello"; // string
typeof 42; // number
typeof null; // objectExplicit Conversion:
Number("10"); // 10
String(50); // "50"
Boolean(0); // falseImplicit (Coercion):
"5" + 1; // "51"
"5" - 1; // 4- Arithmetic:
+ - * / % ** - Comparison:
== != === !== > < >= <= - Logical:
&& || ! - Assignment:
= += -= - Ternary:
condition ? true : false - Nullish Coalescing:
??
- Single-line:
// - Multi-line:
/* ... */ - Use consistent indentation and variable naming.
- Use Prettier or ESLint for formatting.
- What is the difference between
letandconst? - What is the output of
typeof null? - Convert
"50"into a number without usingparseInt(). - What is the result of
"10" - 5 + "5"? - Why is
vardiscouraged in modern JavaScript?
- Which keyword has function-level scope? a) let b) const c) var d) none
- What will
Number(false)return? a) 0 b) 1 c) undefined d) NaN - What is
2 + "2" - 2? a) 22 b) 2 c) 20 d) NaN - Which operator checks both value and type equality?
a)
==b)===c)=d)!=
if / else example:
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}switch example:
switch (color) {
case "red":
console.log("Stop");
break;
case "green":
console.log("Go");
break;
default:
console.log("Invalid color");
}for loop:
for (let i = 1; i <= 3; i++) console.log(i);while loop:
let i = 0;
while (i < 3) {
console.log(i);
i++;
}do...while loop:
let x = 0;
do {
console.log(x);
x++;
} while (x < 2);- break: exits loop immediately.
- continue: skips to next iteration.
for (let i = 0; i < 5; i++) {
if (i === 2) continue;
if (i === 4) break;
console.log(i);
}Output: 0 1 3
try...catch:
try {
let result = riskyOperation();
} catch (err) {
console.log("Error:", err.message);
} finally {
console.log("Execution completed");
}Custom Error:
if (age < 0) throw new Error("Invalid age");- What is the difference between
breakandcontinue? - Write a loop that prints numbers 1–10 but skips even numbers.
- What will happen if an error occurs inside
trywithout acatchblock? - How can you simulate multiple conditions using
switch? - Why is
finallyblock used?
-
What does the following output?
let x = 0; while (x < 3) { if (x === 1) break; console.log(x); x++; }
a) 0 b) 0 1 c) 0 1 2 d) none
-
In which case is the
finallyblock executed? a) Only iftrysucceeds b) Only if an error occurs c) Always d) Never -
What is wrong with this code?
switch (num) { case 1: console.log("One"); case 2: console.log("Two"); }
a) Missing
breakstatements b) Missingdefaultc) Invalid syntax d) None -
Identify the output:
for (let i = 0; i < 3; i++) { if (i === 1) continue; console.log(i); }
a) 0 1 2 b) 0 2 c) 1 2 d) none
✅ End of Module Assessment (Covering Sections 1–3)
- Explain the role of the JavaScript engine and event loop.
- Compare
var,let, andconstin scope and behavior. - Write a function that checks if a number is even using conditional statements.
- Identify three ES6+ features that modernized JavaScript.
- Write a
try...catchexample that safely handles division by zero.