Created @October 29, 2025 12:14 PM
💡 What is JavaScript?
JavaScript is a high-level, interpreted programming language primarily used for
creating dynamic and interactive elements on web pages.
⚙️ Key Features
Runs on the client side in the browser.
Allows developers to manipulate HTML and CSS dynamically.
Enables handling of user events in real time (like clicks, inputs, etc.).
🌐 Modern Usage
Over time, JavaScript has evolved beyond just front-end scripting —
it can now be used on both the front end and back end (via [Link]).
This makes JavaScript a versatile, full-stack language in modern web
development.
⚙️ What is [Link]?
[Link] is an open-source, cross-platform runtime environment that allows
JavaScript to be executed outside of a web browser.
It’s built on Google’s V8 JavaScript engine and is mainly used for building
scalable, fast, and event-driven server-side applications.
⚡ Key Features
Open-source & cross-platform – runs on Windows, macOS, and Linux.
Non-blocking, asynchronous I/O model – handles multiple requests
efficiently.
Event-driven architecture – perfect for real-time applications.
Untitled 1
Built on V8 engine – ensures high performance.
💬 Common Use Cases
Real-time applications like chat systems or live notifications.
APIs and backend services for web or mobile apps.
Streaming servers and microservices architectures.
🧩 JavaScript Data Types
In JavaScript, data types are classified into two main categories:
Primitive and Non-Primitive (Reference) types.
🧠 1. Primitive Data Types
Primitive types store single values and are immutable (cannot be changed
directly).
Type Description Example
String Represents text. "Hello"
Number Represents numeric values. 10 , 3.14
Boolean Represents logical values. true , false
Undefined Declared but not assigned a value. let a;
Null Represents an intentional absence of value. let b = null;
Symbol Used to create unique identifiers. Symbol('id')
BigInt Represents very large integers. 12345678901234567890n
🧩 2. Non-Primitive (Reference) Data Type
Non-primitive types store collections of values or complex entities.
They are mutable and stored by reference.
Untitled 2
Type Description Example
Object A collection of key-value pairs. { name: "Janakiram", age: 21 }
Array Ordered list of values. [1, 2, 3, 4]
Function Block of code that performs a task. function greet() { [Link]("Hi"); }
🧾 Variable
,
var
Declarations in JavaScript —
, and let const
In JavaScript, var , let , and const are used to declare variables —
but they differ in scope, re-declaration, and mutability.
🔸 var
Scope: Function-scoped or globally scoped.
Re-declaration: Allowed within the same scope.
Updating value: Allowed.
Hoisting: Variables declared with var are hoisted to the top but initialized with
undefined .
Limitation: Lacks block scope and can cause unexpected behavior.
✅ Example:
var name = "Janakiram";
var name = "Kusu"; // re-declaration allowed
[Link](name); // Output: Kusu
⚠️ Note:
Because of hoisting and no block scope, var is less preferred in modern
JavaScript.
🔹 let
Untitled 3
Scope: Block-scoped (works only within {} ).
Re-declaration: ❌ Not allowed in the same scope.
Updating value: ✅ Allowed.
Introduced in: ES6 (ECMAScript 2015).
✅ Example:
let age = 20;
age = 21; // allowed
[Link](age); // Output: 21
🔸 const
Scope: Block-scoped.
Re-declaration: ❌ Not allowed.
Updating value: ❌ Not allowed (the reference is constant).
Best for: Constants or variables whose value/reference should not change.
✅ Example:
const PI = 3.14;
PI = 3.1415; // ❌Error: Assignment to constant variable
🧠 Note:
If a const variable holds an object or array, the contents can still be changed (only
the reference is fixed).
const user = { name: "Janakiram" };
[Link] = "Kusu"; // ✅ Allowed
Untitled 4
⚖️ Summary
Feature var let const
Scope Function / Global Block Block
Re-declaration ✅ Yes ❌ No ❌ No
Re-assignment ✅ Yes ✅ Yes ❌ No
Hoisting ✅ Yes (initialized as undefined ) ✅ Yes (in TDZ*) ✅ Yes (in TDZ*)
Preferred? ❌ No ✅ Yes ✅ Yes
👇
🔄 Type Conversion in JavaScript
Type conversion refers to the process of changing a value from one data type to
another.
It can occur in two ways: Implicit (Type Coercion) and Explicit (Manual
Conversion).
⚙️ 1. Implicit Type Conversion (Type Coercion)
When JavaScript automatically converts one data type to another — for
example, when adding a number and a string — it’s called implicit conversion.
"5" + 2; // "52" (Number converted to String)
"5" - 2; // 3 (String converted to Number)
🧠 Note:
JavaScript tries to make sense of the operation by coercing one value’s type to
match the other, which can sometimes lead to unexpected results.
✋ 2. Explicit Type Conversion (Manual Conversion)
Untitled 5
Explicit conversion is when the developer manually converts one type into
another using built-in functions or methods.
🔤 To String Conversion
Method Example Output
Using String() String(123) "123"
Using .toString() (123).toString() "123"
String(123); // "123"
(123).toString(); // "123"
🔢 To Number Conversion
Method Example Output
Using Number() Number("123") 123
Using parseInt() parseInt("123.45") 123
Using parseFloat() parseFloat("123.45") 123.45
Number("123"); // 123
parseInt("123.45"); // 123
parseFloat("123.45"); // 123.45
✅ To Boolean Conversion
Expression Result
Boolean(1) true
Boolean(0) false
🧩 Falsy Values:
0 , "" , null , undefined , NaN , and false
Untitled 6
Everything else is truthy.
Boolean(""); // false
Boolean("Hi"); // true
🧱 To Object Conversion
Primitive values can be converted into their object wrappers using constructors:
new Number(10);
new String("Hello");
new Boolean(true);
🧾 Summary
Conversion Type Common Methods
To String String() , .toString()
To Number Number() , parseInt() , parseFloat()
To Boolean Boolean()
To Object new Number() , new String() , new Boolean()
💡 Tip:
Developers prefer explicit conversion because it makes code more predictable,
readable, and less error-prone than relying on JavaScript’s automatic coercion.
🧮 Operators in JavaScript
Operators are special symbols or keywords used to perform operations on
operands (values or variables).
JavaScript provides various categories of operators to handle arithmetic,
➕
comparison, logic, assignment, and more.
Untitled 7
➕ 1. Arithmetic Operators
Used to perform mathematical operations:
Operator Description Example
+ Addition 5+2=7
- Subtraction 5-2=3
* Multiplication 5 * 2 = 10
/ Division 10 / 2 = 5
% Modulus (Remainder) 10 % 3 = 1
** Exponentiation 2 ** 3 = 8
++ Increment a++ or ++a
-- Decrement a-- or --a
📝 2. Assignment Operators
Used to assign values to variables:
Operator Description Example
= Assign value x = 10
+= Add and assign x += 5 → x = x + 5
-= Subtract and assign x -= 5
*= Multiply and assign x *= 5
/= Divide and assign x /= 5
%= Modulus and assign x %= 5
⚖️ 3. Comparison Operators
Used to compare two values and return a Boolean ( true or false ):
Operator Description Example
== Equal to (compares value only) 5 == "5" → true
=== Strict equal to (compares value & type) 5 === "5" → false
Untitled 8
Operator Description Example
!= Not equal to (value only) 5 != "5" → false
!== Strict not equal to (value & type) 5 !== "5" → true
> Greater than 10 > 5
< Less than 5 < 10
>= Greater than or equal to 10 >= 10
<= Less than or equal to 5 <= 10
🧠 4. Logical Operators
Used to combine or invert conditions:
Operator Description Example
&& Logical AND (x > 0 && y > 0)
` `
! Logical NOT !(x > 0)
⚙️ 5. Bitwise Operators
Operate on binary representations of numbers:
Operator Description Example
& AND 5&1=1
` ` OR
^ XOR 5^1=4
~ NOT ~5 = -6
<< Left Shift 5 << 1 = 10
>> Right Shift 5 >> 1 = 2
❓ 6. Ternary Operator
Used as a shorthand for if-else conditions:
Untitled 9
condition ? value_if_true : value_if_false;
✅ Example:
let result = (age >= 18) ? "Adult" : "Minor";
🧩 7. Type Operators
Operator Description Example
typeof Returns data type of a variable typeof "Hello" → "string"
instanceof Checks if an object is an instance of a class arr instanceof Array → true
🧾 Summary
JavaScript operators enable:
Computation
Decision-making
Logical evaluation
Understanding how and when to use each operator is essential for writing
efficient, clean, and reliable programs.
Conditional Statements and Loops in JavaScript
1. Conditional Statements
Conditional statements are used to perform different actions based on specific
conditions.
a) if Statement
Executes a block of code if a specified condition is true.
Untitled 10
let age = 18;
if (age >= 18) {
[Link]("You are eligible to vote.");
}
b) if...else Statement
Executes one block of code if the condition is true, otherwise executes another
block.
let age = 16;
if (age >= 18) {
[Link]("You are eligible to vote.");
} else {
[Link]("You are not eligible to vote.");
}
c) if...else if...else Statement
Used when multiple conditions need to be checked.
let marks = 75;
if (marks >= 90) {
[Link]("Grade A");
} else if (marks >= 75) {
[Link]("Grade B");
} else {
[Link]("Grade C");
}
d) switch Statement
Untitled 11
Used to select one block of code from multiple alternatives.
let day = 3;
switch (day) {
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
case 3:
[Link]("Wednesday");
break;
default:
[Link]("Invalid day");
}
2. Loops in JavaScript
Loops are used to execute a block of code repeatedly until a specified condition
becomes false.
a) for Loop
Repeats a block of code a specific number of times.
Syntax:
for (initialization; condition; increment/decrement) {
// Code to execute
}
Example:
Untitled 12
for (let i = 1; i <= 5; i++) {
[Link]("Count: " + i);
}
Explanation:
Initialization: let i = 1 → sets the starting point
Condition: i <= 5 → loop runs as long as this is true
Increment: i++ → increases i by 1 after each iteration
Output:
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
b) while Loop
Executes code as long as a condition is true.
let i = 1;
while (i <= 5) {
[Link](i);
i++;
}
c) do...while Loop
Executes the code at least once, even if the condition is false.
Untitled 13
let i = 1;
do {
[Link](i);
i++;
} while (i <= 5);
Summary
Conditional statements control decision-making in programs.
Loops control repetition of code.
The for loop is particularly useful when the number of iterations is known in
advance.
Untitled 14