JS Learn Everything
JS Learn Everything
👉 But: If const holds an object/array, you can still change its contents:
js
const student = { name: "Riya" };
student.name = "Priya"; // ✅ OK
student = {}; // ❌ Error
js
2/36
28/06/2025, 15:10 Complete JS Course Syllabus
{
var x = 5;
let y = 10;
const z = 15;
}
console.log(x); // ✅ 5
console.log(y); // ❌ ReferenceError
console.log(z); // ❌ ReferenceError
🧨 Hoisting
JavaScript prepares memory before running code.
It moves all declarations to the top — this is called hoisting.
But:
var is hoisted and set to undefined
let and const are hoisted but not initialized — so accessing them early gives
ReferenceError
js
console.log(a); // undefined
var a = 10;
js
console.log(b); // ❌ ReferenceError
let b = 20;
3/36
28/06/2025, 15:10 Complete JS Course Syllabus
let and const behave similarly, but const gives more safety — use it when you're not
planning to reassign.
🧠 Mindset Rule
Use const by default. Use let only when you plan to change the value.
Avoid var — it belongs to the past.
🧪 Practice Zone
1. Declare your name and city using const , and your age using let .
2. Try this and observe the result:
js
let x = 5;
let x = 10;
5/36
28/06/2025, 15:10 Complete JS Course Syllabus
🔍 typeof Operator
Used to check the data type of a value:
js
typeof "Sheryians" // "string"
typeof 99 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" ← known bug
typeof [] // "object"
typeof {} // "object"
typeof function(){} // "function"
Note: typeof null === "object" is a bug, but has existed since the early days of JS.
js
5 == "5" // true
5 === "5" // false
Example:
js
if ("0") {
console.log("Runs"); // "0" is a non-empty string = truthy
}
7/36
28/06/2025, 15:10 Complete JS Course Syllabus
🧠 Mindset
JavaScript will often auto-convert types behind the scenes.
Always stay aware of what data type you’re working with.
❓ Common Confusions
typeof null is "object" — this is a bug.
undefined means the variable was never assigned.
🧪 Practice Zone
1. Predict the output:
js
console.log(null + 1);
console.log("5" + 3);
console.log("5" - 3);
console.log(true + false);
2. Check types:
js
console.log(typeof []);
console.log(typeof null);
console.log(typeof 123n);
3. Truthy or Falsy?
js
8/36
28/06/2025, 15:10 Complete JS Course Syllabus
console.log(Boolean(0)); // falsy
console.log(Boolean("0")); // truthy
console.log(Boolean([])); // truthy
console.log(Boolean(undefined));// falsy
4. Write a function isEmpty(value) that checks if a given value is null , undefined , or "" .
5. Compare with loose vs strict:
js
console.log(5 == "5"); // ?
console.log(5 === "5"); // ?
🔄 Chapter 3: Operators
(JavaScript – Learn Everything Series by Sheryians Coding School)
➕ Arithmetic Operators
Used for basic math.
js
+ // addition
- // subtraction
* // multiplication
9/36
28/06/2025, 15:10 Complete JS Course Syllabus
/ // division
% // modulus (remainder)
** // exponentiation (power)
Example:
js
let a = 10, b = 3;
console.log(a + b); // 13
console.log(a % b); // 1
console.log(2 ** 3); // 8
🧮 Assignment Operators
Assign values to variables.
js
= // assigns value
+= // a += b => a = a + b
-= // a -= b
*=, /=, %=
Example:
js
let score = 5;
score += 2; // score = 7
🧾 Comparison Operators
Used in condition checks.
js
10/36
28/06/2025, 15:10 Complete JS Course Syllabus
== // equal (loose)
=== // equal (strict – value + type)
!= // not equal (loose)
!== // not equal (strict)
> < >= <=
Example:
js
console.log(5 == "5"); // true
console.log(5 === "5"); // false
✅ Logical Operators
Used to combine multiple conditions.
js
&& // AND – both must be true
|| // OR – either one true
! // NOT – negates truthiness
Example:
js
let age = 20, hasID = true;
if (age >= 18 && hasID) {
console.log("Allowed");
}
🌀 Unary Operators
Used on a single operand.
js
11/36
28/06/2025, 15:10 Complete JS Course Syllabus
Example:
js
let x = "5";
console.log(+x); // 5 (converted to number)
Example:
js
let score = 80;
let grade = score > 50 ? "Pass" : "Fail";
🧪 typeof Operator
js
typeof 123 // "number"
typeof "hi" // "string"
typeof null // "object" (JS bug)
typeof [] // "object"
12/36
28/06/2025, 15:10 Complete JS Course Syllabus
typeof {} // "object"
typeof function(){} // "function"
🧠 Mindset
Operators make logic happen.
They help you make decisions, combine values, and create expressions.
Try to:
Use === instead of == to avoid type bugs.
Use ternary for quick decisions, not complex ones.
Think in truthy/falsy when using && , || , ! .
❓ Common Confusions
"5" + 1 is "51" (string concat), but "5" - 1 is 4 (number subtract)
!!value is a quick trick to convert anything into a boolean
🧪 Practice Zone
1. Predict:
js
console.log("10" + 1);
console.log("10" - 1);
console.log(true + false);
console.log(!!"Sheryians");
3. Use ternary:
js
let age = 17;
let msg = age >= 18 ? "Adult" : "Minor";
4. Build a calculator:
js
// Using switch + arithmetic operators
function calc(a, b, operator) {
// +, -, *, /
}
5. Score logic:
js
let marks = 82;
// Print "Excellent", "Good", "Average", or "Fail" based on ranges
14/36
28/06/2025, 15:10 Complete JS Course Syllabus
✅ Example:
js
let marks = 78;
🌀 switch-case
Great for checking one variable against many values.
js
15/36
28/06/2025, 15:10 Complete JS Course Syllabus
switch (value) {
case value1:
// code
break;
case value2:
// code
break;
default:
// fallback
}
✅ Example:
js
let fruit = "apple";
switch (fruit) {
case "banana":
console.log("Yellow");
break;
case "apple":
console.log("Red");
break;
default:
console.log("Unknown");
}
16/36
28/06/2025, 15:10 Complete JS Course Syllabus
⚠️ Common Confusions
switch-case executes all cases after a match unless you break
else if chain works top-down — order matters
🧠 Mindset
Control flow = conditional storytelling.
It helps your program make choices and respond differently to different inputs.
Write readable branches. Avoid nesting too deep — use early return if needed.
🧪 Practice Zone
1. Student grade logic:
js
// Write a program that prints A, B, C, D, or F based on marks
2. Rock-paper-scissors:
js
// Given player1 and player2's choice, print winner or draw
3. Login message:
js
17/36
28/06/2025, 15:10 Complete JS Course Syllabus
4. Weather advice:
js
let weather = "rainy";
5. Age checker:
js
// Return "Kid", "Teen", "Adult", or "Senior"
🔁 Chapter 5: Loops
(JavaScript – Learn Everything Series by Sheryians Coding School)
🔄 Why Loops?
Loops help us repeat code without rewriting it.
If a task needs to be done multiple times (e.g., printing 1–10, going through an array, or
checking each character in a string), loops are the backbone.
18/36
28/06/2025, 15:10 Complete JS Course Syllabus
🔁 for Loop
js
for (let i = 0; i < 5; i++) {
console.log(i);
}
Start from i = 0
Run till i < 5
Increase i each time
🔁 while Loop
js
let i = 0;
while (i < 5) {
console.log(i);
i++;
}
🔁 do-while Loop
js
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);
js
for (let i = 1; i <= 5; i++) {
if (i === 3) continue;
console.log(i); // Skips 3
}
🧱 forEach – Arrays
js
let nums = [10, 20, 30];
nums.forEach((num) => {
console.log(num);
});
20/36
28/06/2025, 15:10 Complete JS Course Syllabus
⚠️ Common Confusions
for-in is for objects, not arrays (may cause issues with unexpected keys)
forEach can't use break or continue
🧠 Mindset
Loops = data processor.
Use the right loop for the job:
for = best for numbers/indexes
🧪 Practice Zone
1. Print 1 to 10 using for
2. Print even numbers between 1 to 20
3. Reverse a string using loop
21/36
28/06/2025, 15:10 Complete JS Course Syllabus
🧮 Chapter 6: Functions
(JavaScript – Learn Everything Series by Sheryians Coding School)
🛠️ Function Declarations
js
22/36
28/06/2025, 15:10 Complete JS Course Syllabus
function greet() {
console.log("Welcome to Sheryians!");
}
greet();
🧾 Parameters vs Arguments
js
function greet(name) {
console.log("Hello " + name);
}
greet("Harsh");
name is a parameter
"Harsh" is the argument you pass
🌀 Return Values
js
function sum(a, b) {
return a + b;
}
let total = sum(5, 10); // total is 15
🧰 Function Expressions
23/36
28/06/2025, 15:10 Complete JS Course Syllabus
js
const greet = function () {
console.log("Hello!");
};
🏹 Arrow Functions
js
const greet = () => {
console.log("Hi!");
};
Cleaner syntax
No own this , no arguments object
function sum(...nums) {
return nums.reduce((acc, val) => acc + val, 0);
}
24/36
28/06/2025, 15:10 Complete JS Course Syllabus
a = 1 → default parameter
...nums → rest parameter
🎯 First-Class Functions
JavaScript treats functions as values:
Assign to variables
Pass as arguments
Return from other functions
js
function shout(msg) {
return msg.toUpperCase();
}
function processMessage(fn) {
console.log(fn("hello"));
}
processMessage(shout);
25/36
28/06/2025, 15:10 Complete JS Course Syllabus
26/36
28/06/2025, 15:10 Complete JS Course Syllabus
greet(); // error
const greet = function () {
console.log("Hi");
};
⚠️ Common Confusions
Arrow functions don’t have their own this
You can’t break out of forEach
Closures often trap old variable values
Return vs console.log – don't mix them up
🧠 Mindset
Functions are your logic blocks + memory holders (via closure).
They keep your code clean, DRY, and reusable.
🧪 Practice Zone
1. Write a BMI calculator function
2. Create a greet function with default name
3. Sum all numbers using rest parameter
4. Create a closure counter function
5. Write a function that returns another function
6. Use a function to log even numbers in array
7. Create a pure function to add tax
27/36
28/06/2025, 15:10 Complete JS Course Syllabus
🧰 Chapter 7: Arrays
(JavaScript – Learn Everything Series by Sheryians Coding School)
🧠 What is an Array?
An array is like a row of boxes, where each box holds a value and has an index (0, 1, 2…).
Arrays help you store multiple values in a single variable — numbers, strings, or even
objects/functions.
js
let fruits = ["apple", "banana", "mango"];
28/36
28/06/2025, 15:10 Complete JS Course Syllabus
🔄 Iteration Methods
map()
Returns a new array with modified values.
js
let prices = [100, 200, 300];
let taxed = prices.map(p => p * 1.18);
filter()
29/36
28/06/2025, 15:10 Complete JS Course Syllabus
reduce()
Reduces the array to a single value.
js
let total = nums.reduce((acc, val) => acc + val, 0);
forEach()
Performs an action for each element (but returns undefined).
js
nums.forEach(n => console.log(n));
30/36
28/06/2025, 15:10 Complete JS Course Syllabus
⚠️ Common Confusions
splice changes original array, slice does not
forEach vs map : map returns a new array
js
[10, 2, 3].sort(); // [10, 2, 3] → ["10", "2", "3"] → wrong order
Use:
js
arr.sort((a, b) => a - b); // Correct numeric sort
🧠 Mindset
Arrays are structured, transformable data.
You loop over them, transform them, filter them, or reduce them — all to control what shows up
in your UI or logic.
🧪 Practice Zone
1. Create an array of student names and print each
2. Filter even numbers from an array
3. Map prices to include GST (18%)
4. Reduce salaries to calculate total payroll
5. Find the first student with grade A
6. Write a function to reverse an array
7. Sort array of ages in ascending order
31/36
28/06/2025, 15:10 Complete JS Course Syllabus
🧱 Chapter 8: Objects
(JavaScript – Learn Everything Series by Sheryians Coding School)
🧠 What is an Object?
Objects in JavaScript are like real-world records – a collection of key-value pairs.
They help us store structured data (like a student, a product, or a user profile).
js
let student = {
name: "Ravi",
age: 21,
isEnrolled: true
};
🔑 Key-Value Structure
Keys are always strings (even if you write them as numbers or identifiers)
Values can be anything – string, number, array, object, function, etc.
js
console.log(student["name"]); // Ravi
console.log(student.age); // 21
32/36
28/06/2025, 15:10 Complete JS Course Syllabus
console.log(user.address.city); // Delhi
✂️ Object Destructuring
You can extract values directly:
js
let { name, age } = student;
js
let {
address: { city }
} = user;
📦 Copying Objects
Shallow Copy (one level deep)
js
let newStudent = { ...student };
let newOne = Object.assign({}, student);
34/36
28/06/2025, 15:10 Complete JS Course Syllabus
❗ Note: JSON-based copy works only for plain data (no functions, undefined, etc.)
❓ Optional Chaining
Avoids errors if a nested property is undefined:
js
console.log(user?.address?.city); // Delhi
console.log(user?.profile?.email); // undefined (no error)
🧠 Computed Properties
You can use variables as keys:
js
let key = "marks";
let report = {
[key]: 89
};
⚠️ Common Confusions
Shallow copy copies only the first level
for-in includes inherited keys (be cautious!)
🧠 Mindset
35/36
28/06/2025, 15:10 Complete JS Course Syllabus
Objects are structured state – perfect for modeling anything complex: a user, a form, a product,
etc.
Use destructuring, chaining, and dynamic keys wisely.
🧪 Practice Zone
1. Create an object for a book (title, author, price)
2. Access properties using both dot and bracket
3. Write a nested object (user with address and location)
4. Destructure name and age from a student object
5. Loop through keys and values of an object
6. Convert object to array using Object.entries()
7. Copy an object using spread operator
8. Create a deep copy of an object with nested structure
9. Use optional chaining to safely access deep values
10. Use a variable as a key using computed properties
36/36