๐ ๐๐ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐๐ผ๐๐ฟ๐๐ฒ ๐| ๐๐ฒ๐ฐ๐ผ๐บ๐ฒ ๐ฎ๐ป ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ
This AI engineering course online is structured around AI fundamentals, full-stack development, real-world AI projects
๐ซ2000+ Students Placed
๐ฅ Live Classes + Session Recordings
๐จโ๐ป 1:1 Mentorship & Doubt Support
๐ผ Interview Preparation & Placement Assistance
๐๐ผ๐ผ๐ธ ๐ฎ ๐๐ฅ๐๐ ๐๐ฒ๐บ๐ผ๐:-
โ
https://pdlink.in/4fWJVID
๐ฅ Take the next step towards building your career in AI!
This AI engineering course online is structured around AI fundamentals, full-stack development, real-world AI projects
๐ซ2000+ Students Placed
๐ฅ Live Classes + Session Recordings
๐จโ๐ป 1:1 Mentorship & Doubt Support
๐ผ Interview Preparation & Placement Assistance
๐๐ผ๐ผ๐ธ ๐ฎ ๐๐ฅ๐๐ ๐๐ฒ๐บ๐ผ๐:-
โ
https://pdlink.in/4fWJVID
๐ฅ Take the next step towards building your career in AI!
โค1
๐ป JavaScript Learning Series, Day 2
Topic 2: Variables & Data Types in JavaScript
Today, we'll learn how to store information in JavaScript and understand the different types of data we can work with.
1. What Are Variables?
A variable is a named container used to store data in a program.
For example:
Output:
Here:
โข name stores a string.
โข age stores a number.
โข salary stores a number.
2. How to Declare Variables
JavaScript provides three main ways to declare variables.
A. var
โข Function-scoped.
โข Can be redeclared.
โข Can be reassigned.
โข Generally avoided in modern JavaScript.
B. let
โข Block-scoped.
โข Cannot be redeclared in the same scope.
โข Can be reassigned.
Output: 30
C. const
โข Block-scoped.
โข Cannot be redeclared in the same scope.
โข Cannot be reassigned.
Output: India
Remember: A const object or array can still have its contents modified. The variable binding itself cannot be reassigned.
3. Difference Between var, let & const
Best Practice: Use const by default and let when reassignment is required. Avoid var in modern JavaScript.
4. JavaScript Data Types
JavaScript has two broad categories of data types.
A. Primitive Data Types
There are seven primitive types.
1. String
Used to store text.
2. Number
Used for integers and decimal values.
3. Boolean
Stores either true or false.
4. Undefined
A variable that has been declared but not assigned a value.
Output: undefined
5. Null
Represents an intentional absence of a value.
6. BigInt
Used for integers larger than the safe integer limit of the Number type.
7. Symbol
Creates unique identifiers.
B. Non-Primitive Data Types
These are commonly represented using objects.
1. Object
Stores data in key-value pairs.
2. Array
Stores multiple values in an ordered collection.
3. Function
A reusable block of code.
5. Checking Data Types Using typeof
JavaScript provides the typeof operator to identify the type of a value.
Important:
6. Dynamic Typing in JavaScript
JavaScript is dynamically typed. This means a variable can hold different types of values during execution.
The same variable first stores a number and then stores a string.
7. Type Conversion
Type conversion means converting one data type into another.
String to Number
Topic 2: Variables & Data Types in JavaScript
Today, we'll learn how to store information in JavaScript and understand the different types of data we can work with.
1. What Are Variables?
A variable is a named container used to store data in a program.
For example:
let name = "John";
let age = 25;
let salary = 45000;
console.log(name);
console.log(age);
console.log(salary);
Output:
John
25
45000
Here:
โข name stores a string.
โข age stores a number.
โข salary stores a number.
2. How to Declare Variables
JavaScript provides three main ways to declare variables.
A. var
โข Function-scoped.
โข Can be redeclared.
โข Can be reassigned.
โข Generally avoided in modern JavaScript.
var city = "Mumbai";
var city = "Pune";
console.log(city);
B. let
โข Block-scoped.
โข Cannot be redeclared in the same scope.
โข Can be reassigned.
let age = 25;
age = 30;
console.log(age);
Output: 30
C. const
โข Block-scoped.
โข Cannot be redeclared in the same scope.
โข Cannot be reassigned.
const country = "India";
console.log(country);
Output: India
Remember: A const object or array can still have its contents modified. The variable binding itself cannot be reassigned.
3. Difference Between var, let & const
Feature: Scope
var: Function
let: Block
const: Block
Feature: Reassignment
var: Yes
let: Yes
const: No
Feature: Redeclaration
var: Yes
let: No
const: No
Feature: Hoisting
var: Yes
let: Yes
const: Yes
Feature: Initialization required
var: No
let: No
const: Yes
Best Practice: Use const by default and let when reassignment is required. Avoid var in modern JavaScript.
4. JavaScript Data Types
JavaScript has two broad categories of data types.
A. Primitive Data Types
There are seven primitive types.
1. String
Used to store text.
let name = "Rahul";
2. Number
Used for integers and decimal values.
let age = 25;
let price = 99.99;
3. Boolean
Stores either true or false.
let isActive = true;
let isCompleted = false;
4. Undefined
A variable that has been declared but not assigned a value.
let result;
console.log(result);
Output: undefined
5. Null
Represents an intentional absence of a value.
let selectedUser = null;
6. BigInt
Used for integers larger than the safe integer limit of the Number type.
let bigNumber = 12345678901234567890n;
7. Symbol
Creates unique identifiers.
let id = Symbol("user");
B. Non-Primitive Data Types
These are commonly represented using objects.
1. Object
Stores data in key-value pairs.
let student = {
name: "Rahul",
age: 22,
city: "Delhi"
};
2. Array
Stores multiple values in an ordered collection.
let fruits = ["Apple", "Mango", "Banana"];
3. Function
A reusable block of code.
function greet() {
console.log("Hello!");
}
5. Checking Data Types Using typeof
JavaScript provides the typeof operator to identify the type of a value.
console.log(typeof "Hello");
console.log(typeof 100);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof 100n);
console.log(typeof Symbol("id"));
console.log(typeof {});
string
number
boolean
undefined
bigint
symbol
object
Important:
typeof null also returns "object". This is a historical JavaScript behavior.6. Dynamic Typing in JavaScript
JavaScript is dynamically typed. This means a variable can hold different types of values during execution.
let data = 100;
console.log(data);
data = "Hello JavaScript";
console.log(data);
100
Hello JavaScript
The same variable first stores a number and then stores a string.
7. Type Conversion
Type conversion means converting one data type into another.
String to Number
โค3
let value = "100";
let result = Number(value);
Output: 100
Number to String
let age = 25;
let result = String(age);
Output:
25 (as a string)String to Boolean
let value = "Hello";
console.log(Boolean(value));
Output: true
8. Variable Naming Rules
Follow these rules when naming variables:
- Names can contain letters, numbers,
_ and $.- Names cannot start with a number.
- Variable names are case-sensitive.
- Reserved keywords cannot be used as variable names.
- Use meaningful names.
Good examples:
let firstName = "Rahul";
let totalPrice = 500;
let isLoggedIn = true;
Invalid examples:
let 1name = "Rahul";
let let = 100;
Double Tap โค๏ธ For Part-3
โค8
๐๐ข๐ข๐๐๐ ๐ฑ ๐๐ฅ๐๐ ๐ง๐๐๐ ๐๐ข๐จ๐ฅ๐ฆ๐๐ฆ ๐ฎ๐ฌ๐ฎ๐ฒ! ๐๐ป
Explore 5 FREE Google learning courses to build in-demand technical skills and strengthen your resume! ๐
โ FREE Learning Resources
โ Beginner-Friendly Courses
โ Learn at Your Own Pace
โ Explore Hands-On Learning Opportunities
โ Build Skills for AI, ML & Cloud Careers
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4kMcA5X
โก Don't wait to upgrade your skills โ start learning today!
Explore 5 FREE Google learning courses to build in-demand technical skills and strengthen your resume! ๐
โ FREE Learning Resources
โ Beginner-Friendly Courses
โ Learn at Your Own Pace
โ Explore Hands-On Learning Opportunities
โ Build Skills for AI, ML & Cloud Careers
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4kMcA5X
โก Don't wait to upgrade your skills โ start learning today!
โค1
๐ ๐ ๐๐๐ฅ๐ข๐ฆ๐ข๐๐ง + ๐๐๐ก๐๐๐๐๐ก ๐๐ฅ๐๐ ๐๐ข๐จ๐ฅ๐ฆ๐๐ฆ! ๐๐ฅ
๐ Explore 5 FREE Career Learning Paths to boost your resume!
๐ Data Analytics | โ๏ธ Cloud Computing | ๐ค AI | ๐ Cybersecurity | ๐ป Software Development
โ Learn In-Demand Skills
โ Explore Certificate Opportunities
โ Perfect for Students, Freshers & Job Seekers
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4eOufX9
๐ฒ Share with your friends! ๐ฅ
๐ Explore 5 FREE Career Learning Paths to boost your resume!
๐ Data Analytics | โ๏ธ Cloud Computing | ๐ค AI | ๐ Cybersecurity | ๐ป Software Development
โ Learn In-Demand Skills
โ Explore Certificate Opportunities
โ Perfect for Students, Freshers & Job Seekers
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4eOufX9
๐ฒ Share with your friends! ๐ฅ
โค3
๐ป JavaScript Learning Series - Day 4
Topic 4: Conditional Statements in JavaScript
Conditional statements allow a program to make decisions based on whether a condition is true or false.
For example:
โข Check whether a person is eligible to vote.
โข Check whether a student has passed or failed.
โข Verify login credentials.
โข Apply discounts based on purchase amounts.
1. The if Statement
The
statement executes a block of code only when a condition is true.
Syntax:
Example:
Output: You are eligible to vote
2. The if-else Statement
Executes one block when the condition is true and another when it is false.
Output: Not eligible to vote
3. The else-if Statement
Used when you need to check multiple conditions.
Example: Student Grading System
Output: Grade B
4. Nested if Statements
An
statement inside another
statement is called a nested
statement.
Example: Login Verification
Output: Login Successful
5. The switch Statement
Used when you want to compare one expression against multiple possible values.
Example: Day of the Week
Output: Wednesday
Remember:
โข
defines possible matching values.
โข
prevents execution from falling through to the next case.
โข
executes when no case matches.
6. Ternary Operator
A shorter way to write a simple if-else condition.
Output:
7. Multiple Conditions Using Logical Operators
AND (&&)
Both conditions must be true.
OR (||)
At least one condition must be true.
NOT (!)
Reverses a Boolean condition.
8. Real-World Example: Online Shopping Discount
Output:
Topic 4: Conditional Statements in JavaScript
Conditional statements allow a program to make decisions based on whether a condition is true or false.
For example:
โข Check whether a person is eligible to vote.
โข Check whether a student has passed or failed.
โข Verify login credentials.
โข Apply discounts based on purchase amounts.
1. The if Statement
The
if
statement executes a block of code only when a condition is true.
Syntax:
if (condition) {
// Code executes if condition is true
}Example:
let age = 20;
if (age >= 18) {
console.log("You are eligible to vote");
}
Output: You are eligible to vote
2. The if-else Statement
Executes one block when the condition is true and another when it is false.
let age = 16;
if (age >= 18) {
console.log("Eligible to vote");
} else {
console.log("Not eligible to vote");
}
Output: Not eligible to vote
3. The else-if Statement
Used when you need to check multiple conditions.
Example: Student Grading System
let marks = 85;
if (marks >= 90) {
console.log("Grade A");
} else if (marks >= 75) {
console.log("Grade B");
} else if (marks >= 60) {
console.log("Grade C");
} else if (marks >= 40) {
console.log("Grade D");
} else {
console.log("Fail");
}
Output: Grade B
4. Nested if Statements
An
if
statement inside another
if
statement is called a nested
if
statement.
Example: Login Verification
let username = "admin";
let password = "12345";
if (username === "admin") {
if (password === "12345") {
console.log("Login Successful");
} else {
console.log("Incorrect Password");
}
} else {
console.log("Invalid Username");
}
Output: Login Successful
5. The switch Statement
Used when you want to compare one expression against multiple possible values.
switch (expression) {
case value1:
// Code
break;
case value2:
// Code
break;
default:
// Default code
}Example: Day of the Week
let day = 3;
switch (day) {
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
break;
case 3:
console.log("Wednesday");
break;
default:
console.log("Invalid Day");
}
Output: Wednesday
Remember:
โข
case
defines possible matching values.
โข
break
prevents execution from falling through to the next case.
โข
default
executes when no case matches.
6. Ternary Operator
A shorter way to write a simple if-else condition.
condition ? expression1 : expression2;
let age = 21;
let result = age >= 18
? "Adult"
: "Minor";
console.log(result);
Output:
Adult
7. Multiple Conditions Using Logical Operators
AND (&&)
Both conditions must be true.
let age = 25;
let hasLicense = true;
if (age >= 18 && hasLicense) {
console.log("You can drive");
}
OR (||)
At least one condition must be true.
let isWeekend = false;
let isHoliday = true;
if (isWeekend || isHoliday) {
console.log("It's a day off");
}
NOT (!)
Reverses a Boolean condition.
let isLoggedIn = false;
if (!isLoggedIn) {
console.log("Please log in");
}
8. Real-World Example: Online Shopping Discount
let purchaseAmount = 5000;
let discount = 0;
if (purchaseAmount >= 5000) {
discount = 20;
} else if (purchaseAmount >= 3000) {
discount = 10;
} else if (purchaseAmount >= 1000) {
discount = 5;
}
let finalAmount =
purchaseAmount - (purchaseAmount * discount / 100);
console.log("Purchase:", purchaseAmount);
console.log("Discount:", discount + "%");
console.log("Final Amount:", finalAmount);
Output:
Purchase: 5000
Discount: 20%
Final Amount: 4000
โค4
9. Types of Conditional Statements
๐น
๐น
๐น
โ Checks multiple conditions.
๐น Nested if โ Checks dependent conditions inside another condition.
๐น switch โ Matches an expression against multiple possible values.
Double Tap โค๏ธ For Part-5
๐น
if โ Checks one condition.๐น
if-else โ Chooses between two possible paths.๐น
else-if
โ Checks multiple conditions.
๐น Nested if โ Checks dependent conditions inside another condition.
๐น switch โ Matches an expression against multiple possible values.
Double Tap โค๏ธ For Part-5
โค7
๐ ๐ฐ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ฎ๐๐ถ๐ผ๐ป๐ ๐ง๐ผ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐๐ป ๐ฎ๐ฌ๐ฎ๐ฒ ๐
Want to build job-ready skills and strengthen your resume? Start learning these in-demand technologies
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐ :- https://pdlink.in/45vk5ph
๐ซ ๐๐๐น๐น๐๐๐ฎ๐ฐ๐ธ :- https://pdlink.in/3SuUeuD
โ๏ธ ๐๐ฎ๐๐ฎ ๐ฆ๐ฐ๐ถ๐ฒ๐ป๐ฐ๐ฒ :- :- https://pdlink.in/48kyZjt
๐ก๏ธ ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ถ๐ป๐ด :- :- https://pdlink.in/4fWJVID
๐ ๐ฆ๐ต๐ฎ๐ฟ๐ฒ this with your friends and classmates!
Want to build job-ready skills and strengthen your resume? Start learning these in-demand technologies
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐ :- https://pdlink.in/45vk5ph
๐ซ ๐๐๐น๐น๐๐๐ฎ๐ฐ๐ธ :- https://pdlink.in/3SuUeuD
โ๏ธ ๐๐ฎ๐๐ฎ ๐ฆ๐ฐ๐ถ๐ฒ๐ป๐ฐ๐ฒ :- :- https://pdlink.in/48kyZjt
๐ก๏ธ ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ถ๐ป๐ด :- :- https://pdlink.in/4fWJVID
๐ ๐ฆ๐ต๐ฎ๐ฟ๐ฒ this with your friends and classmates!
๐๐ฅ๐๐ข๐ข๐๐๐ ๐๐๐ข๐จ๐ โ ๐ฐ ๐๐ฅ๐๐ ๐๐ข๐จ๐ฅ๐ฆ๐๐ฆ! โ๏ธ๐
Learn *Data Analytics, BigQuery, Data Engineering & Looker* for FREE!
โ Beginner-Friendly Learning
โ Build In-Demand Tech Skills
โ Boost Your Resume & Career Opportunities
๐ฏ Perfect for Students, Freshers & Job Seekers!
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4AttkUb
๐ฒ Save & Share with your friends! ๐ฅ
Learn *Data Analytics, BigQuery, Data Engineering & Looker* for FREE!
โ Beginner-Friendly Learning
โ Build In-Demand Tech Skills
โ Boost Your Resume & Career Opportunities
๐ฏ Perfect for Students, Freshers & Job Seekers!
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4AttkUb
๐ฒ Save & Share with your friends! ๐ฅ
โค1๐1
๐ป JavaScript Learning Series: Day 5
Topic 5: Loops in JavaScript
Loops execute a block of code repeatedly while a condition is met. They save you from writing the same code over and over.
Without a loop:
Using a loop:
Both produce the same output, but loops make code shorter and easier to maintain.
1. for Loop
A for loop is useful when you know how many times you want to run a block of code.
Syntax:
The three parts are:
โข Initialization sets the starting value.
โข Condition checks whether the loop should continue.
โข Update changes the variable after each iteration.
Example:
Output:
Here, i starts at 1, increases by 1 after each iteration, and the loop ends when i <= 5 is false.
2. while Loop
A while loop runs as long as its condition is true. Itโs useful when you donโt know exactly how many iterations are needed.
The condition is checked before each iteration. Make sure the loop can eventually end, or it may run forever.
3.
A
Key difference:
โข
โข
โข
4.
Use
Example: iterating through an array:
Example: iterating through a string:
This prints each character separately.
5.
Use
6. Nested Loops
A nested loop is a loop inside another loop. Itโs commonly used for patterns, matrices, and multidimensional arrays.
Topic 5: Loops in JavaScript
Loops execute a block of code repeatedly while a condition is met. They save you from writing the same code over and over.
Without a loop:
console.log("Hello");
console.log("Hello");
console.log("Hello");
console.log("Hello");
console.log("Hello");Using a loop:
for (let i = 1; i <= 5; i++) {
console.log("Hello");
}Both produce the same output, but loops make code shorter and easier to maintain.
1. for Loop
A for loop is useful when you know how many times you want to run a block of code.
Syntax:
for (initialization; condition; update) {
// Code to execute
}The three parts are:
โข Initialization sets the starting value.
โข Condition checks whether the loop should continue.
โข Update changes the variable after each iteration.
Example:
for (let i = 1; i <= 5; i++) {
console.log(i);
}Output:
1
2
3
4
5
Here, i starts at 1, increases by 1 after each iteration, and the loop ends when i <= 5 is false.
2. while Loop
A while loop runs as long as its condition is true. Itโs useful when you donโt know exactly how many iterations are needed.
while (condition) {
// Code to execute
}let i = 1;
while (i <= 5) {
console.log(i);
i++;
}
The condition is checked before each iteration. Make sure the loop can eventually end, or it may run forever.
3.
do...while LoopA
do...while loop runs its code at least once before checking the condition.do {
// Code to execute
} while (condition);do {
console.log(i);
i++;
} while (i <= 5);Key difference:
โข
for is commonly used when the number of iterations is known.โข
while checks the condition before running the code.โข
do...while runs the code once before checking the condition.4.
for...of LoopUse
for...of to iterate over values in iterables such as arrays, strings, maps, and sets.Example: iterating through an array:
let fruits = ["Apple", "Mango", "Banana"];
for (let fruit of fruits) {
console.log(fruit);
}
Apple
Mango
Banana
Example: iterating through a string:
let name = "JavaScript";
for (let character of name) {
console.log(character);
}
This prints each character separately.
5.
for...in LoopUse
for...in to iterate over an object's enumerable property keys.let student = {
name: "Rahul",
age: 22,
city: "Delhi"
};
for (let key in student) {
console.log(key, student[key]);
}name Rahul
age 22
city Delhi
key is the property name, and student[key] retrieves its value. For arrays, prefer for...of or array methods.6. Nested Loops
A nested loop is a loop inside another loop. Itโs commonly used for patterns, matrices, and multidimensional arrays.
for (let i = 1; i <= 3; i++) {
for (let j = 1; j <= 3; j++) {
console.log(i, j);
}
}1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
โค3
The inner loop completes all its iterations for each iteration of the outer loop.
7.
```text
1
2
3
4
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue;
}
console.log(i);
}
1
2
4
5
let salaries = [25000, 30000, 35000, 40000];
let total = 0;
for (let salary of salaries) {
total += salary;
}
console.log("Total Salary:", total);
Total Salary: 130000
for (let i = 2; i <= 10; i += 2) {
console.log(i);
}
for (let i = 10; i >= 1; i--) {
console.log(i);
}
let sum = 0;
for (let i = 1; i <= 10; i++) {
sum += i;
}
console.log(sum);
55
let number = 5;
for (let i = 1; i <= 10; i++) {
console.log(number + " x " + i + " = " + (number * i));
}
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50
11. Common Mistakes to Avoid
โข Forgetting to update the loop variable.
โข Using the wrong loop condition.
โข Accidentally creating an infinite loop.
โข Confusing
โข Using
โข Making nested loops more complicated than necessary.
โข Using
12. Quick Revision: Types of Loops
๐น
๐น
๐น
๐น
๐น
๐น Nested loop โ A loop inside another loop.
๐น
๐น
Key Takeaways
โข Loops automate repetitive tasks.
โข Know when to use
โข Use
โข Use
โข Practice nested loops and common coding patterns.
Double Tap โค๏ธ For More
7.
break Statementbreak immediately ends the loop.for (let i = 1; i <= 10; i++) {
if (i === 5) {
break;
}
console.log(i);
}```text
1
2
3
4
javascript
When i becomes 5, the loop stops.
8. continue Statement
continue skips the current iteration and moves to the next one.
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue;
}
console.log(i);
}
text
1
2
4
5
javascript
The loop skips 3 but continues running.
9. Real-World Example: Calculate Total Salary
let salaries = [25000, 30000, 35000, 40000];
let total = 0;
for (let salary of salaries) {
total += salary;
}
console.log("Total Salary:", total);
text
Total Salary: 130000
javascript
The loop visits each salary and adds it to the total.
10. Common Loop Patterns
A. Print even numbers
for (let i = 2; i <= 10; i += 2) {
console.log(i);
}
javascript
Output: 2, 4, 6, 8, 10
B. Print numbers in reverse
for (let i = 10; i >= 1; i--) {
console.log(i);
}
javascript
C. Calculate the sum of numbers
let sum = 0;
for (let i = 1; i <= 10; i++) {
sum += i;
}
console.log(sum);
text
55
javascript
D. Print a multiplication table
let number = 5;
for (let i = 1; i <= 10; i++) {
console.log(number + " x " + i + " = " + (number * i));
}
text
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50
`11. Common Mistakes to Avoid
โข Forgetting to update the loop variable.
โข Using the wrong loop condition.
โข Accidentally creating an infinite loop.
โข Confusing
break with continue.โข Using
for...in unnecessarily for arrays.โข Making nested loops more complicated than necessary.
โข Using
<= instead of < when it causes an extra iteration.12. Quick Revision: Types of Loops
๐น
for loop โ Best when the number of iterations is known.๐น
while loop โ Repeats while a condition remains true.๐น
do...while loop โ Runs at least once before checking the condition.๐น
for...of loop โ Iterates over values in iterable objects.๐น
for...in loop โ Iterates over enumerable property keys.๐น Nested loop โ A loop inside another loop.
๐น
break โ Terminates the loop.๐น
continue โ Skips the current iteration.Key Takeaways
โข Loops automate repetitive tasks.
โข Know when to use
for, while, and do...while.โข Use
for...of for iterable values and for...in for object property keys.โข Use
break to stop a loop and continue to skip an iteration.โข Practice nested loops and common coding patterns.
Double Tap โค๏ธ For More
โค1
๐ฏ ๐๐ฅ๐๐ ๐๐๐ฏ๐ฆ๐ฝ๐ผ๐ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป๐ ๐ณ๐ผ๐ฟ ๐ฆ๐๐๐ฑ๐ฒ๐ป๐๐ & ๐๐ฟ๐ฒ๐๐ต๐ฒ๐ฟ๐ ๐ถ๐ป ๐ฎ๐ฌ๐ฎ๐ฒ๐
๐ซHubSpot Academy offers three free online certifications that match these interests.
๐ซPick one free course and try it out on your next college event and the certification is free.
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4iM5xaQ
๐ฒ *Save & Share with your friends! ๐ฅ*
๐ซHubSpot Academy offers three free online certifications that match these interests.
๐ซPick one free course and try it out on your next college event and the certification is free.
๐ ๐๐ถ๐ป๐ธ :- ๐
https://pdlink.in/4iM5xaQ
๐ฒ *Save & Share with your friends! ๐ฅ*
โค2
๐๐ฅ๐๐ ๐ฅ๐ฒ๐๐ผ๐๐ฟ๐ฐ๐ฒ๐ ๐ง๐ผ ๐๐ฒ๐ ๐ฌ๐ผ๐๐ฟ ๐๐ฟ๐ฒ๐ฎ๐บ ๐๐ผ๐ฏ ๐๐ก ๐๐ผ๐ผ๐ด๐น๐ฒ๐ฅ
Discover *4 FREE resources* to help you prepare for a career at Google!
โ Improve Your Coding Skills
โ Strengthen Interview Preparation
โ Build Technical Knowledge
โ Prepare for Top Tech Opportunities
๐Perfect for Students, Freshers & Aspiring Software Engineers!
๐ ๐๐ถ๐ป๐ธ ๐:-
https://pdlink.in/4AwRPQy
๐ฒ SAVE & SHARE with friends dreaming of working at Google!
Discover *4 FREE resources* to help you prepare for a career at Google!
โ Improve Your Coding Skills
โ Strengthen Interview Preparation
โ Build Technical Knowledge
โ Prepare for Top Tech Opportunities
๐Perfect for Students, Freshers & Aspiring Software Engineers!
๐ ๐๐ถ๐ป๐ธ ๐:-
https://pdlink.in/4AwRPQy
๐ฒ SAVE & SHARE with friends dreaming of working at Google!
โค1
๐๐ฅ๐๐ ๐ฉ๐๐ฅ๐ง๐จ๐๐ ๐๐ก๐ง๐๐ฅ๐ก๐ฆ๐๐๐ฃ๐ฆ ๐ช๐๐ง๐ ๐ง๐ข๐ฃ ๐๐ข๐ ๐ฃ๐๐ก๐๐๐ฆ! ๐
๐ป Explore FREE Virtual Internship & Job Simulation Programs from leading companies!
โ Learn Industry-Relevant Skills
โ Work on Practical Tasks
โ Self-Paced Online Learning
โ Explore Completion Certificates
โ Strengthen Your Resume & LinkedIn Profile
๐ฏ Perfect for Students, Freshers & Job Seekers
๐ ๐๐ถ๐ป๐ธ ๐:-
https://pdlink.in/4t8DRlq
๐ฒ SAVE & SHARE with friends looking for career opportunities!
๐ป Explore FREE Virtual Internship & Job Simulation Programs from leading companies!
โ Learn Industry-Relevant Skills
โ Work on Practical Tasks
โ Self-Paced Online Learning
โ Explore Completion Certificates
โ Strengthen Your Resume & LinkedIn Profile
๐ฏ Perfect for Students, Freshers & Job Seekers
๐ ๐๐ถ๐ป๐ธ ๐:-
https://pdlink.in/4t8DRlq
๐ฒ SAVE & SHARE with friends looking for career opportunities!
๐ฐ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐ง๐ผ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐๐
๐ฐ๐ฒ๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐ ๐
๐ Explore 4 FREE Excel Courses to upgrade your skills!
โ Excel Formulas & Functions
โ Pivot Tables & Charts
โ Data Cleaning & Analysis
โ Dashboards & Reporting
๐ฏ Perfect for Students, Freshers & Aspiring Data Analysts!
๐ ๐๐ถ๐ป๐ธ ๐:-
https://pdlink.in/48mO4B2
๐ SAVE & SHARE with friends who want to master Excel! ๐ฅ
๐ Explore 4 FREE Excel Courses to upgrade your skills!
โ Excel Formulas & Functions
โ Pivot Tables & Charts
โ Data Cleaning & Analysis
โ Dashboards & Reporting
๐ฏ Perfect for Students, Freshers & Aspiring Data Analysts!
๐ ๐๐ถ๐ป๐ธ ๐:-
https://pdlink.in/48mO4B2
๐ SAVE & SHARE with friends who want to master Excel! ๐ฅ
๐ป JavaScript Learning Series - Day 6
Topic 6: Functions in JavaScript
Functions are one of the most important concepts in JavaScript.
A function is a reusable block of code designed to perform a specific task.
Instead of writing the same code repeatedly, you can create a function and execute it whenever needed.
For example:
โข Calculate employee salaries.
โข Validate user login details.
โข Calculate shopping discounts.
โข Process customer information.
โข Perform mathematical calculations.
Let's understand functions step by step.
1. What Is a Function?
A function is a block of code that performs a particular task when called.
Output:
Explanation:
โข
โข
โข
โข
โข
Important: Defining a function does not automatically execute it. You must call it.
2. Function Declaration
A function declaration defines a function using the
Syntax:
Example:
Output:
Function declarations can generally be called before their definition because they are hoisted.
3. Functions with Parameters
Parameters allow you to pass information into a function.
Output:
Here:
โข
โข
Difference:
Parameter โ Variable listed in the function definition.
Argument โ Actual value passed when calling the function.
4. Functions with Return Values
The
Output:
โข The function receives two values.
โข It adds them.
โข
โข The result is stored in the
Important:
5. Function Expression
A function expression stores a function inside a variable.
Output:
Unlike function declarations, function expressions assigned to variables cannot generally be called before their initialization.
6. Arrow Functions
Arrow functions provide a shorter syntax for writing functions.
They were introduced in ES6.
Traditional function:
Arrow function:
Output:
For a single expression, you can write:
Output:
Topic 6: Functions in JavaScript
Functions are one of the most important concepts in JavaScript.
A function is a reusable block of code designed to perform a specific task.
Instead of writing the same code repeatedly, you can create a function and execute it whenever needed.
For example:
โข Calculate employee salaries.
โข Validate user login details.
โข Calculate shopping discounts.
โข Process customer information.
โข Perform mathematical calculations.
Let's understand functions step by step.
1. What Is a Function?
A function is a block of code that performs a particular task when called.
function greet() {
console.log("Hello, Welcome!");
}
greet();Output:
Hello, Welcome!
Explanation:
โข
function โ Keyword used to declare a function.โข
greet โ Function name.โข
() โ Holds parameters, if required.โข
{} โ Contains the function's code.โข
greet() โ Calls or executes the function.Important: Defining a function does not automatically execute it. You must call it.
2. Function Declaration
A function declaration defines a function using the
function keyword.Syntax:
function functionName() {
// Code to execute
}Example:
function welcome() {
console.log("Welcome to JavaScript");
}
welcome();Output:
Welcome to JavaScript
Function declarations can generally be called before their definition because they are hoisted.
3. Functions with Parameters
Parameters allow you to pass information into a function.
function greet(name) {
console.log("Hello " + name);
}
greet("Rahul");
greet("Priya");Output:
Hello Rahul
Hello Priya
Here:
โข
name is a parameter.โข
"Rahul" and "Priya" are arguments.Difference:
Parameter โ Variable listed in the function definition.
Argument โ Actual value passed when calling the function.
4. Functions with Return Values
The
return statement sends a value back from a function.function add(a, b) {
return a + b;
}
let result = add(10, 20);
console.log(result);Output:
30
โข The function receives two values.
โข It adds them.
โข
return sends the result back.โข The result is stored in the
result variable.Important:
return also terminates the function's execution.5. Function Expression
A function expression stores a function inside a variable.
const greet = function() {
console.log("Hello JavaScript");
};
greet();Output:
Hello JavaScript
Unlike function declarations, function expressions assigned to variables cannot generally be called before their initialization.
6. Arrow Functions
Arrow functions provide a shorter syntax for writing functions.
They were introduced in ES6.
Traditional function:
function add(a, b) {
return a + b;
}Arrow function:
const add = (a, b) => {
return a + b;
};
console.log(add(10, 20));Output:
30
For a single expression, you can write:
const add = (a, b) => a + b;
console.log(add(5, 10));
Output:
15
Arrow functions are commonly used in modern JavaScript, callbacks, and array methods.
Note: Arrow functions do not have their own
7. Anonymous Functions
An anonymous function is a function without a name.
Output after approximately 2 seconds:
Anonymous functions are frequently used as callbacks.
8. Default Parameters
Default parameters provide fallback values when an argument is missing or
Output:
9. Rest Parameters
Rest parameters allow a function to accept multiple arguments and collect them into an array.
Output:
Here,
10. Callback Functions
A callback is a function passed as an argument to another function.
Output:
Callbacks are widely used in:
โข Event handling.
โข Asynchronous programming.
โข Array methods.
โข API operations.
11. Immediately Invoked Function Expression (IIFE)
An IIFE is a function that executes immediately after it is defined.
Output:
IIFEs were traditionally used to create private scopes and avoid polluting the global namespace.
12. Function Scope
Scope determines where a variable can be accessed.
JavaScript has different types of scope.
A. Global Scope
Variables declared outside functions and blocks may be accessible throughout their containing script or module environment.
B. Function Scope
Variables declared with
C. Block Scope
Variables declared using
13. Higher-Order Functions
A higher-order function is a function that accepts another function as an argument or returns a function.
Higher-order functions are widely used in functional programming and array operations.
14. Real-World Example: Employee Salary Calculator
Note: Arrow functions do not have their own
this binding.7. Anonymous Functions
An anonymous function is a function without a name.
setTimeout(function() {
console.log("Hello after 2 seconds");
}, 2000);Output after approximately 2 seconds:
Hello after 2 seconds
Anonymous functions are frequently used as callbacks.
8. Default Parameters
Default parameters provide fallback values when an argument is missing or
undefined.function greet(name = "Guest") {
console.log("Hello " + name);
}
greet("Rahul");
greet();Output:
Hello Rahul
Hello Guest
9. Rest Parameters
Rest parameters allow a function to accept multiple arguments and collect them into an array.
function calculateTotal(...numbers) {
let total = 0;
for (let num of numbers) {
total += num;
}
return total;
}
console.log(calculateTotal(10, 20, 30, 40));Output:
100
Here,
...numbers collects all the supplied arguments into one array.10. Callback Functions
A callback is a function passed as an argument to another function.
function greet(name, callback) {
console.log("Hello " + name);
callback();
}
function message() {
console.log("Welcome to JavaScript");
}
greet("Rahul", message);Output:
Hello Rahul
Welcome to JavaScript
Callbacks are widely used in:
โข Event handling.
โข Asynchronous programming.
โข Array methods.
โข API operations.
11. Immediately Invoked Function Expression (IIFE)
An IIFE is a function that executes immediately after it is defined.
(function() {
console.log("Function executed immediately");
})();Output:
Function executed immediately
IIFEs were traditionally used to create private scopes and avoid polluting the global namespace.
12. Function Scope
Scope determines where a variable can be accessed.
JavaScript has different types of scope.
A. Global Scope
Variables declared outside functions and blocks may be accessible throughout their containing script or module environment.
let name = "Rahul";
function greet() {
console.log(name);
}
B. Function Scope
Variables declared with
var inside a function are accessible within that function.function test() {
var age = 25;
console.log(age);
}
test();C. Block Scope
Variables declared using
let and const inside a block are accessible only within that block.if (true) {
let age = 25;
const city = "Delhi";
}
console.log(age); // ReferenceError13. Higher-Order Functions
A higher-order function is a function that accepts another function as an argument or returns a function.
function calculate(a, b, operation) {
return operation(a, b);
}
function add(x, y) {
return x + y;
}
console.log(calculate(10, 20, add));Higher-order functions are widely used in functional programming and array operations.
14. Real-World Example: Employee Salary Calculator
โค2
function calculateSalary(basicSalary, bonus) {
let totalSalary = basicSalary + bonus;
return totalSalary;
}
function displaySalary(name, salary) {
console.log("Employee:", name);
console.log("Total Salary:", salary);
}
let salary = calculateSalary(50000, 10000);
displaySalary("Rahul", salary);Output:
Employee: Rahul
Total Salary: 60000
This example demonstrates how functions help organize and reuse business logic.
15. Common Mistakes Beginners Should Avoid
โข Forgetting to call a function after declaring it.
โข Confusing parameters with arguments.
โข Forgetting the
return statement.โข Using variables outside their scope.
โข Confusing arrow functions with regular functions.
โข Passing incorrect arguments.
โข Creating unnecessarily large functions.
โข Forgetting that a function without an explicit return statement returns
undefined.16. Quick Revision: Types of Functions
๐น Function Declaration โ Defines a function using the
function keyword.๐น Function Expression โ Stores a function inside a variable.
๐น Arrow Function โ Provides shorter function syntax.
๐น Anonymous Function โ Function without a name.
๐น Callback Function โ Function passed as an argument to another function.
๐น IIFE โ Function that executes immediately after definition.
๐น Higher-Order Function โ Accepts or returns another function.
๐น Recursive Function โ A function that calls itself.
Key Takeaways
โข Functions make code reusable and organized.
โข Parameters allow functions to accept input.
โข Return statements send results back.
โข Arrow functions simplify function syntax.
โข Callbacks allow functions to work with other functions.
โข Scope determines variable accessibility.
โข Higher-order functions are important in modern JavaScript.
Double Tap โค๏ธ For More
โค4