JavaScript Session 14 Notes
🔶 What is JavaScript?
- JavaScript is a lightweight, interpreted scripting language used to create dynamic and
interactive content on web pages.
- It runs in the browser (client-side) but can also be used on the server-side using
environments like Node.js.
📜 JavaScript History
- Developed by Brendan Eich in 1995 at Netscape.
- Originally named Mocha, then LiveScript, and finally JavaScript.
- Standardized by ECMA International as ECMAScript (ES) in 1997.
🔁 JavaScript & ECMAScript
- JavaScript is the programming language.
- ECMAScript is the standard specification JavaScript follows.
- Different browsers implement ECMAScript, with each JavaScript engine (like V8 in
Chrome) supporting specific versions.
📅 JavaScript Versions
- ES1 to ES5 (1997–2009): Basic features like functions, arrays, objects.
- ES6 (2015): Major update – let, const, arrow functions, classes, promises.
- ES7 to ES14 (2016–2023): Added async/await, optional chaining, nullish coalescing, etc.
🔤 Syntax Review
- Case-sensitive
- Statements end with a semicolon (;)
- Blocks are grouped with curly braces {}
Example:
let name = "Bhavyasree";
console.log(name);
🔑 Keywords & Reserved Words
- Keywords: var, let, const, if, else, while, for, function, etc.
- Reserved words (can't be used as identifiers): class, enum, super, implements, interface,
etc.
📦 Variable Declaration
- var: Old, function-scoped
- let: Block-scoped, ES6+
- const: Block-scoped, constant values
🌐 Variable Scope
- Global Scope: Declared outside any function or block.
- Function Scope: Declared inside a function (with var).
- Block Scope: Declared inside {} using let or const.
📍 Block Scope
- Introduced with let and const in ES6.
- Variables declared in {} can't be accessed outside the block.
🔢 Primitive Values
- Stored by value
- Types: string, number, boolean, null, undefined, symbol, bigint
📚 Reference Values
- Stored by reference
- Objects, arrays, functions
🔣 Types
- Primitive: string, number, boolean, null, undefined, symbol, bigint
- Reference: object, array, function
🔁 Type Conversion
- Implicit: JS automatically converts (e.g., "5" + 2 becomes "52")
- Explicit: Using functions like Number(), String()
🧮 Expressions in JavaScript
- Arithmetic: +, -, *, /, %, **
- Relational: >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, etc.
- Others: ternary ? :, typeof, instanceof
➕ Operators Overview
Arithmetic: +, -, *, /, %, **
Relational: <, >, <=, >=, ==, !=
Logical: &&, ||, !
Assignment: =, +=, -=, *=, /=, %=
Bitwise: &, |, ^, ~, <<, >>
🔁 Flow Control and Conditionals
- if, else if, else
- switch-case
🔄 Loops & Iteration
- for loop
- while loop
- do...while loop
- for...of (arrays), for...in (objects)
⛔ Jump Statements
- break: Exit from loop or switch.
- continue: Skip to next iteration.
- return: Exit from function.
- throw: Throws an error.