๐น Escape Characters
2๏ธโฃ5๏ธโฃ New Line
You can use
๐น Comparing Strings
2๏ธโฃ6๏ธโฃ String Comparison
Strings can be compared:
โญ Practical String Processing
Imagine a user enters an email:
This combines:
โข
๐ง Real-World Example
Suppose you receive this data:
โ ๏ธ Common Beginner Mistakes
โข Mistake 1: Forgetting that strings are zero-indexed
โข Mistake 2: Expecting string methods to modify the original string
โข
Mistake 3: Forgetting
โข User input often has accidental spaces:
โข
Mistake 4: Confusing
โข
โข
๐ป Practice
โข
1๏ธโฃ Reverse a String: Given
โข
2๏ธโฃ Count Characters: Count characters in
โข
3๏ธโฃ Convert to Uppercase: Convert
โข
4๏ธโฃ Extract Text: From
โข
5๏ธโฃ Replace Text: Convert
โข
6๏ธโฃ Clean User Input: Given
โข
7๏ธโฃ Challenge: Given
Create a cleaned version that:
- Removes extra spaces
- Converts everything to lowercase
- Checks whether it contains
- Prints
๐ง Double Tap โค๏ธ For More
2๏ธโฃ5๏ธโฃ New Line
You can use
\n and \t:const message1 = "Hello\nWorld";
console.log(message1);
// Hello
// World
const message2 = "Name:\tRahul";
console.log(message2); // Name: Rahul (with tab)
๐น Comparing Strings
2๏ธโฃ6๏ธโฃ String Comparison
Strings can be compared:
console.log("apple" === "apple"); // true
console.log("Apple" === "apple"); // false - case-sensitive
const input = "ADMIN";
if (input.toLowerCase() === "admin") {
console.log("Access granted");
}โญ Practical String Processing
Imagine a user enters an email:
const input = " USER@GMAIL.COM ";
const email = input.trim().toLowerCase();
console.log(email); // user@gmail.com
if (email.includes("@")) {
console.log("Email looks valid");
}
This combines:
โข
trim() โ toLowerCase() โ includes()๐ง Real-World Example
Suppose you receive this data:
const data = "Amit, Priya, Rahul, Neha";
const names = data.split(",");
const cleanedNames = names.map(name => name.trim());
console.log(cleanedNames); // ["Amit", "Priya", "Rahul", "Neha"]
const filteredNames = cleanedNames.filter(
name => name.startsWith("R")
);
console.log(filteredNames); // ["Rahul"]
โ ๏ธ Common Beginner Mistakes
โข Mistake 1: Forgetting that strings are zero-indexed
const word = "Hello";
console.log(word[0]); // H not e
โข Mistake 2: Expecting string methods to modify the original string
const name = "rahul";
name.toUpperCase();
console.log(name); // still "rahul"
const upperName = name.toUpperCase(); // correct
โข
Mistake 3: Forgetting
trim()โข User input often has accidental spaces:
" Rahul "โข
Mistake 4: Confusing
split() and join()โข
split() โ string โ arrayโข
join() โ array โ string๐ป Practice
โข
1๏ธโฃ Reverse a String: Given
const word = "JavaScript"; Try to produce tpircSavaJ. Hint: split() + reverse() + join()โข
2๏ธโฃ Count Characters: Count characters in
"JavaScript"โข
3๏ธโฃ Convert to Uppercase: Convert
"javascript is powerful" to uppercase.โข
4๏ธโฃ Extract Text: From
"JavaScript" extract Scriptโข
5๏ธโฃ Replace Text: Convert
"I love Python" into "I love JavaScript"โข
6๏ธโฃ Clean User Input: Given
const input = " HELLO JAVASCRIPT "; Produce hello javascriptโข
7๏ธโฃ Challenge: Given
const email = " USER@EXAMPLE.COM "; Create a cleaned version that:
- Removes extra spaces
- Converts everything to lowercase
- Checks whether it contains
@- Prints
"Valid email format" if it does.๐ง Double Tap โค๏ธ For More
โค7
10 Websites Every Developer & AI Enthusiast Should Bookmark
โ roadmap.sh โ Step-by-step learning paths for devs
โ paperswithcode.com โ Browse ML research with code implementations
โ devdocs.io โ Offline access to all developer documentation
โ excalidraw.com โ Create whiteboard-style diagrams for planning
โ codewars.com โ Improve coding skills with challenges
โ vectara.com โ Build RAG apps with AI-powered search
โ openai.com/blog โ Stay updated with the latest AI research
โ learnprompting.org โ Master the art of prompt engineering
โ hackertarget.com โ Useful for cybersecurity testing tools
If you want more free resources like this React with emoji and turn all notification ๐ข
Join @free4unow_backup for more free resources.
ENJOY LEARNING ๐๐
โ roadmap.sh โ Step-by-step learning paths for devs
โ paperswithcode.com โ Browse ML research with code implementations
โ devdocs.io โ Offline access to all developer documentation
โ excalidraw.com โ Create whiteboard-style diagrams for planning
โ codewars.com โ Improve coding skills with challenges
โ vectara.com โ Build RAG apps with AI-powered search
โ openai.com/blog โ Stay updated with the latest AI research
โ learnprompting.org โ Master the art of prompt engineering
โ hackertarget.com โ Useful for cybersecurity testing tools
If you want more free resources like this React with emoji and turn all notification ๐ข
Join @free4unow_backup for more free resources.
ENJOY LEARNING ๐๐
โค10๐ฅ4๐2
To learn web design and development from basic to advanced levels, you can follow these steps: ๐คฉ๐คฉ
โฉ HTML and CSS:
Start with the basics of HTML (Hypertext Markup Language) and CSS (Cascading Style Sheets). HTML provides the structure and content of web pages, while CSS handles the visual presentation. Learn how to create web pages, format text, add images, and apply styles using HTML and CSS.
โฉ JavaScript:
Expand your knowledge by learning JavaScript, a programming language for web development. JavaScript adds interactivity and dynamic features to websites. Study JavaScript concepts like variables, functions, loops, and conditional statements. Learn how to manipulate the Document Object Model (DOM) and create interactive elements.
โฉ Responsive Web Design:
Understand the principles of responsive web design, which ensures websites adapt to different screen sizes and devices. Learn techniques such as media queries and flexible layouts to create responsive and mobile-friendly websites.
โฉ Front-End Frameworks:
Explore popular front-end frameworks like Bootstrap or Foundation. These frameworks provide pre-built components and a responsive grid system, making it easier to design and develop modern, visually appealing websites.
โฉ Back-End Development:
Dive into back-end development to create dynamic websites and handle server-side operations. Learn a back-end programming language such as Python, PHP, or Node.js. Understand concepts like server-side scripting, handling databases, and interacting with APIs.
โฉ Database Management:
Gain knowledge of database management systems such as MySQL or PostgreSQL. Understand how to create, manage, and query databases, as well as the principles of database design and normalization.
โฉ Content Management Systems (CMS):
Explore popular CMS platforms like WordPress, Joomla, or Drupal. Learn how to customize and develop themes, create plugins or modules, and manage website content using CMS tools.
โฉ Version Control:
Familiarize yourself with version control systems like Git. Learn how to track changes, collaborate with others, and manage your codebase effectively using version control.
โฉ Web Performance and Optimization:
Study techniques for optimizing website performance, such as optimizing images, minifying CSS and JavaScript files, and caching. Understand concepts like page speed, performance testing, and website optimization best practices.
โฉ Continuous Learning and Industry Trends:
Stay updated with the latest web design and development trends, technologies, and tools. Follow blogs, forums, and online communities to learn from industry experts and explore new advancements.
โก๏ธ Build Projects and Practice:
Put your knowledge into practice by building projects and websites. Start with small projects and gradually work on more complex ones. Building real-world projects will help you gain practical experience and refine your skills.
Web design and development is a vast field, and continuous learning is key. Practice regularly, experiment with different techniques, and don't be afraid to take on challenges.
React โค๏ธ for more
โฉ HTML and CSS:
Start with the basics of HTML (Hypertext Markup Language) and CSS (Cascading Style Sheets). HTML provides the structure and content of web pages, while CSS handles the visual presentation. Learn how to create web pages, format text, add images, and apply styles using HTML and CSS.
โฉ JavaScript:
Expand your knowledge by learning JavaScript, a programming language for web development. JavaScript adds interactivity and dynamic features to websites. Study JavaScript concepts like variables, functions, loops, and conditional statements. Learn how to manipulate the Document Object Model (DOM) and create interactive elements.
โฉ Responsive Web Design:
Understand the principles of responsive web design, which ensures websites adapt to different screen sizes and devices. Learn techniques such as media queries and flexible layouts to create responsive and mobile-friendly websites.
โฉ Front-End Frameworks:
Explore popular front-end frameworks like Bootstrap or Foundation. These frameworks provide pre-built components and a responsive grid system, making it easier to design and develop modern, visually appealing websites.
โฉ Back-End Development:
Dive into back-end development to create dynamic websites and handle server-side operations. Learn a back-end programming language such as Python, PHP, or Node.js. Understand concepts like server-side scripting, handling databases, and interacting with APIs.
โฉ Database Management:
Gain knowledge of database management systems such as MySQL or PostgreSQL. Understand how to create, manage, and query databases, as well as the principles of database design and normalization.
โฉ Content Management Systems (CMS):
Explore popular CMS platforms like WordPress, Joomla, or Drupal. Learn how to customize and develop themes, create plugins or modules, and manage website content using CMS tools.
โฉ Version Control:
Familiarize yourself with version control systems like Git. Learn how to track changes, collaborate with others, and manage your codebase effectively using version control.
โฉ Web Performance and Optimization:
Study techniques for optimizing website performance, such as optimizing images, minifying CSS and JavaScript files, and caching. Understand concepts like page speed, performance testing, and website optimization best practices.
โฉ Continuous Learning and Industry Trends:
Stay updated with the latest web design and development trends, technologies, and tools. Follow blogs, forums, and online communities to learn from industry experts and explore new advancements.
โก๏ธ Build Projects and Practice:
Put your knowledge into practice by building projects and websites. Start with small projects and gradually work on more complex ones. Building real-world projects will help you gain practical experience and refine your skills.
Web design and development is a vast field, and continuous learning is key. Practice regularly, experiment with different techniques, and don't be afraid to take on challenges.
React โค๏ธ for more
โค19
๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ฃ๐ผ๐๐ฒ๐ฟ ๐๐ ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐! ๐ฅ
Learn Power BI through these FREE learning resources
โ
โจ What You'll Learn:
๐ Interactive Dashboards
๐ Data Visualization
๐งน Data Transformation
๐ผ Real-World Reporting Skills
๐ฏ Beginner-Friendly โ No Coding Required
๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐
โ
โhttps://pdlink.in/4hznwlu
๐ซPerfect for Students โข Freshers โข Data Analyst Aspirants โข Working Professionals
Learn Power BI through these FREE learning resources
โ
โจ What You'll Learn:
๐ Interactive Dashboards
๐ Data Visualization
๐งน Data Transformation
๐ผ Real-World Reporting Skills
๐ฏ Beginner-Friendly โ No Coding Required
๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐
โ
โhttps://pdlink.in/4hznwlu
๐ซPerfect for Students โข Freshers โข Data Analyst Aspirants โข Working Professionals
โค5
๐๐ฃ๐ฎ๐ ๐๐ณ๐๐ฒ๐ฟ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐ง๐ฟ๐ฎ๐ถ๐ป๐ถ๐ป๐ด | ๐๐ฒ๐ฐ๐ผ๐บ๐ฒ ๐ฎ ๐๐๐น๐น๐๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ ๐ช๐๐๐ต ๐๐ฒ๐ป๐๐
Start a high-paying tech careerโeven without prior coding experience
๐ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ hiring partners
โ 100% job assistance
๐ Skill Indiaโauthenticated certificate
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐๐:-
https://pdlink.in/3SuUeuD
๐ฏ HurryUp.....Limited Seats Available
Start a high-paying tech careerโeven without prior coding experience
๐ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ hiring partners
โ 100% job assistance
๐ Skill Indiaโauthenticated certificate
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐๐:-
https://pdlink.in/3SuUeuD
๐ฏ HurryUp.....Limited Seats Available
โค2
๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ถ๐๐ต ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ฒ๐! ๐๐ฅ
Upgrade your resume with Microsoft learning opportunities. Explore courses covering some of today's most in-demand tech skills!
๐ฏ Perfect for Students โข Freshers โข Job Seekers โข Working Professionals
โ Learn at your own pace โ Build career-relevant skills โ Explore available certificates and credentials
๐ ๐๐ฐ๐ฐ๐ฒ๐๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ฒ๐ฟ๐ฒ ๐
https://pdlink.in/3Uf5trR
๐ฅ Share with friends looking to upskill in 2026!
Upgrade your resume with Microsoft learning opportunities. Explore courses covering some of today's most in-demand tech skills!
๐ฏ Perfect for Students โข Freshers โข Job Seekers โข Working Professionals
โ Learn at your own pace โ Build career-relevant skills โ Explore available certificates and credentials
๐ ๐๐ฐ๐ฐ๐ฒ๐๐ ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ผ๐ณ๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐๐ฒ๐ฟ๐ฒ ๐
https://pdlink.in/3Uf5trR
๐ฅ Share with friends looking to upskill in 2026!
โค1
๐ฎ๐ณ ๐๐ข๐ฉ๐๐ฅ๐ก๐ ๐๐ก๐ง ๐ข๐ ๐๐ก๐๐๐ โ ๐๐๐๐ง๐ ๐๐ก๐ง๐๐ฅ๐ก๐ฆ๐๐๐ฃ๐ฆ ๐ฎ๐ฌ๐ฎ๐ฒ ๐
Students and freshers can explore internship opportunities through the AICTE Internship Portal across multiple domains:
๐ป AI, Data Science & Web Development
๐ Digital Marketing & Business Development
๐ฐ Finance & Accounting
โ๏ธ Content Writing & Graphic Design
โ๏ธ Mechanical, Civil & Electrical Engineering
๐ ๐๐ต๐ฒ๐ฐ๐ธ ๐ข๐ฝ๐ฝ๐ผ๐ฟ๐๐๐ป๐ถ๐๐ถ๐ฒ๐ & ๐๐ฝ๐ฝ๐น๐ ๐
https://pdlink.in/4y3vcBl
๐ข Share this opportunity with your friends and classmates!
Students and freshers can explore internship opportunities through the AICTE Internship Portal across multiple domains:
๐ป AI, Data Science & Web Development
๐ Digital Marketing & Business Development
๐ฐ Finance & Accounting
โ๏ธ Content Writing & Graphic Design
โ๏ธ Mechanical, Civil & Electrical Engineering
๐ ๐๐ต๐ฒ๐ฐ๐ธ ๐ข๐ฝ๐ฝ๐ผ๐ฟ๐๐๐ป๐ถ๐๐ถ๐ฒ๐ & ๐๐ฝ๐ฝ๐น๐ ๐
https://pdlink.in/4y3vcBl
๐ข Share this opportunity with your friends and classmates!
โค3๐2
๐ ๐ช๐ต๐ถ๐ฐ๐ต ๐ง๐ฒ๐ฐ๐ต ๐ฆ๐ธ๐ถ๐น๐น ๐ช๐ถ๐น๐น ๐ฌ๐ผ๐ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ถ๐ป ๐ฎ๐ฌ๐ฎ๐ฒ?
Want to build apps, uncover insights, or create AI solutions? Explore certification courses that match your career goals! ๐ฏ
๐ป ๐๐๐น๐น ๐ฆ๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐บ๐ฒ๐ป๐
๐ https://pdlink.in/3SuUeuD
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐
๐ https://pdlink.in/45vk5ph
๐ซ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ถ๐ป๐ด
๐ https://pdlink.in/4fWJVID
๐ฅ Choose your path, sharpen your skills, and take the next step towards your tech career!
๐ Save this post & share it with a friend planning to upskill.
Want to build apps, uncover insights, or create AI solutions? Explore certification courses that match your career goals! ๐ฏ
๐ป ๐๐๐น๐น ๐ฆ๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐บ๐ฒ๐ป๐
๐ https://pdlink.in/3SuUeuD
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐
๐ https://pdlink.in/45vk5ph
๐ซ๐๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ถ๐ป๐ด
๐ https://pdlink.in/4fWJVID
๐ฅ Choose your path, sharpen your skills, and take the next step towards your tech career!
๐ Save this post & share it with a friend planning to upskill.
โค1
๐ป JavaScript Roadmap 2026 โ Part 9
๐ก Scope, Hoisting & Execution Context
Now we're moving from basic JavaScript syntax into concepts that explain how JavaScript actually executes your code.
These concepts are extremely important because they explain things like:
โข Why some variables are accessible in certain places but not others
โข Why functions can sometimes be called before they are written
โข Why "let" and "const" behave differently from "var"
โข How JavaScript manages function calls
โข How nested functions access variables from outer functions
1๏ธโฃ What Is Scope?
Scope determines where a variable can be accessed in your program.
For example:
The variable "name" is accessible here because it was declared in the outer scope.
But:
"message" is available inside "greet()".
Trying to access it outside:
causes an error because "message" belongs to the function's local scope.
2๏ธโฃ Global Scope
A variable declared outside functions and blocks is generally in the global/module scope depending on how your JavaScript is executed.
Example:
Output:
The function can access "appName" because the variable exists in an outer scope.
3๏ธโฃ Function Scope
Variables declared inside a function are accessible within that function.
This works.
But:
doesn't work because "price" exists only inside "calculate()".
4๏ธโฃ Block Scope
A block is code surrounded by "{}".
For example:
"message" exists inside that block.
But:
causes an error.
Variables declared using:
โข let
โข const
are block-scoped.
5๏ธโฃ "var" and Block Scope
This is one reason "var" can cause confusing behavior.
This can print:
because "var" is not block-scoped.
Compare:
This causes an error because "let" is block-scoped.
Remember:
โข var โ function-scoped
โข let โ block-scoped
โข const โ block-scoped
6๏ธโฃ Lexical Scope
JavaScript uses lexical scoping.
This means the scope of a variable is determined by where the code is written, not where the function is eventually called.
Example:
"inner()" can access "name" because "name" exists in an outer lexical scope.
7๏ธโฃ Scope Chain
What happens if JavaScript can't find a variable in the current scope?
It looks outward.
Example:
๐ก Scope, Hoisting & Execution Context
Now we're moving from basic JavaScript syntax into concepts that explain how JavaScript actually executes your code.
These concepts are extremely important because they explain things like:
โข Why some variables are accessible in certain places but not others
โข Why functions can sometimes be called before they are written
โข Why "let" and "const" behave differently from "var"
โข How JavaScript manages function calls
โข How nested functions access variables from outer functions
1๏ธโฃ What Is Scope?
Scope determines where a variable can be accessed in your program.
For example:
let name = "Rahul";
console.log(name);
The variable "name" is accessible here because it was declared in the outer scope.
But:
function greet() {
let message = "Hello";
console.log(message);
}
greet();"message" is available inside "greet()".
Trying to access it outside:
console.log(message);
causes an error because "message" belongs to the function's local scope.
2๏ธโฃ Global Scope
A variable declared outside functions and blocks is generally in the global/module scope depending on how your JavaScript is executed.
Example:
const appName = "My App";
function showAppName() {
console.log(appName);
}
showAppName();
Output:
My App
The function can access "appName" because the variable exists in an outer scope.
3๏ธโฃ Function Scope
Variables declared inside a function are accessible within that function.
function calculate() {
const price = 1000;
console.log(price);
}
calculate();This works.
But:
console.log(price);
doesn't work because "price" exists only inside "calculate()".
4๏ธโฃ Block Scope
A block is code surrounded by "{}".
For example:
if (true) {
let message = "Hello";
console.log(message);
}"message" exists inside that block.
But:
console.log(message);
causes an error.
Variables declared using:
โข let
โข const
are block-scoped.
5๏ธโฃ "var" and Block Scope
This is one reason "var" can cause confusing behavior.
if (true) {
var message = "Hello";
}
console.log(message);This can print:
Hello
because "var" is not block-scoped.
Compare:
if (true) {
let message = "Hello";
}
console.log(message);This causes an error because "let" is block-scoped.
Remember:
โข var โ function-scoped
โข let โ block-scoped
โข const โ block-scoped
6๏ธโฃ Lexical Scope
JavaScript uses lexical scoping.
This means the scope of a variable is determined by where the code is written, not where the function is eventually called.
Example:
const name = "Rahul";
function outer() {
function inner() {
console.log(name);
}
inner();
}
outer();
"inner()" can access "name" because "name" exists in an outer lexical scope.
7๏ธโฃ Scope Chain
What happens if JavaScript can't find a variable in the current scope?
It looks outward.
Example:
const country = "India";
function outer() {
const city = "Pune";
function inner() {
const name = "Rahul";
console.log(name);
console.log(city);
console.log(country);
}
inner();
}
outer();
โค1
When "inner()" looks for:
it finds it in its own scope.
For:
JavaScript looks in the outer scope.
For:
it goes one level further outward.
Conceptually:
This is the scope chain.
8๏ธโฃ What Is Hoisting?
Hoisting describes how JavaScript's execution process makes certain declarations available before their position in the source code is reached.
But different declarations behave differently.
This is why you should avoid thinking of hoisting as simply:
"JavaScript moves all code to the top."
That's not an accurate mental model.
9๏ธโฃ Function Declaration Hoisting
Function declarations can be called before their declaration in the same scope.
Output:
The function declaration is available when execution begins.
๐ "var" Hoisting
Consider:
The result is:
Conceptually, you can think of the declaration being initialized early:
The important point is:
before normal execution reaches the assignment.
1๏ธโฃ1๏ธโฃ "let" and "const" Hoisting
Now consider:
This produces a
The same applies to:
Why?
"let" and "const" declarations are created during the setup phase, but they aren't initialized until execution reaches their declaration.
The period between entering the scope and initialization is called the:
Temporal Dead Zone (TDZ)
1๏ธโฃ2๏ธโฃ Temporal Dead Zone
Example:
The variable "name" exists in the scope, but accessing it before initialization causes an error.
Conceptually:
So:
is not equivalent to using "var".
1๏ธโฃ3๏ธโฃ Why "let" and "const" Are Safer
Compare:
Output:
versus:
Error:
The error makes the problem much easier to detect instead of silently giving you
1๏ธโฃ4๏ธโฃ Function Scope vs Block Scope Example
Consider:
This works because "b" is function-scoped.
But:
nameit finds it in its own scope.
For:
cityJavaScript looks in the outer scope.
For:
countryit goes one level further outward.
Conceptually:
inner scope
โ
outer scope
โ
global/module scope
This is the scope chain.
8๏ธโฃ What Is Hoisting?
Hoisting describes how JavaScript's execution process makes certain declarations available before their position in the source code is reached.
But different declarations behave differently.
This is why you should avoid thinking of hoisting as simply:
"JavaScript moves all code to the top."
That's not an accurate mental model.
9๏ธโฃ Function Declaration Hoisting
Function declarations can be called before their declaration in the same scope.
greet();
function greet() {
console.log("Hello");
}
Output:
Hello
The function declaration is available when execution begins.
๐ "var" Hoisting
Consider:
console.log(age);
var age = 25;
The result is:
undefined
Conceptually, you can think of the declaration being initialized early:
var age;
console.log(age);
age = 25;
The important point is:
var declaration โ initialized as undefinedbefore normal execution reaches the assignment.
1๏ธโฃ1๏ธโฃ "let" and "const" Hoisting
Now consider:
console.log(age);
let age = 25;
This produces a
ReferenceError.The same applies to:
console.log(age);
const age = 25;
Why?
"let" and "const" declarations are created during the setup phase, but they aren't initialized until execution reaches their declaration.
The period between entering the scope and initialization is called the:
Temporal Dead Zone (TDZ)
1๏ธโฃ2๏ธโฃ Temporal Dead Zone
Example:
{
console.log(name);
let name = "Rahul";
}The variable "name" exists in the scope, but accessing it before initialization causes an error.
Conceptually:
Block begins
โ
name exists but is uninitialized
โ
Temporal Dead Zone
โ
let name = "Rahul"
โ
name becomes initialized
So:
console.log(name);
let name = "Rahul";
is not equivalent to using "var".
1๏ธโฃ3๏ธโฃ Why "let" and "const" Are Safer
Compare:
console.log(value);
var value = 10;
Output:
undefined
versus:
console.log(value);
let value = 10;
Error:
ReferenceError
The error makes the problem much easier to detect instead of silently giving you
undefined.1๏ธโฃ4๏ธโฃ Function Scope vs Block Scope Example
Consider:
function test() {
if (true) {
let a = 10;
var b = 20;
}
console.log(b);
}
test();This works because "b" is function-scoped.
But:
function test() {
if (true) {
let a = 10;
}
console.log(a);
}doesn't work because "a" is block-scoped.
โญ 1๏ธโฃ5๏ธโฃ What Is an Execution Context?
When JavaScript runs code, it creates an execution context.
An execution context is the environment in which JavaScript evaluates and executes code.
At a high level, there are different kinds of execution contexts.
The most important ones initially are:
โข Global Execution Context: Created when your JavaScript program begins executing.
โข Function Execution Context: Created whenever a function is called.
For example:
Conceptually:
1๏ธโฃ6๏ธโฃ Creation Phase and Execution Phase
A simplified mental model is that JavaScript prepares an execution context before executing its statements.
During setup, JavaScript determines things such as:
โข Variable bindings
โข Function declarations
โข Lexical environments
Then JavaScript executes the code.
For example:
During the setup process, JavaScript prepares the relevant bindings.
Then execution proceeds through the statements.
This helps explain why function declarations and "var" behave differently from "let" and "const".
1๏ธโฃ7๏ธโฃ Execution Context Stack
JavaScript uses a call stack to keep track of active function execution.
Example:
The execution roughly looks like:
When "third()" finishes:
Then:
Then:
Eventually the stack becomes empty.
โญ 1๏ธโฃ8๏ธโฃ Call Stack
The call stack follows:
LIFO (Last In, First Out)
For:
The stack conceptually becomes:
1. Global
2. first()
3. second()
Then:
Global continues
Understanding the call stack becomes very important when we later study:
โข Callbacks
โข Asynchronous JavaScript
โข Promises
โข Event loop
โข Stack overflow
โญ 1๏ธโฃ9๏ธโฃ Scope vs Execution Context
These concepts are related but not identical.
โข Scope answers: "Where can this variable be accessed?"
โข Execution context answers more broadly: "What environment is JavaScript using while executing this code?"
For example:
Scope determines which variables are accessible.
Execution context represents the environment created when "greet()" is actually executed.
โญ 2๏ธโฃ0๏ธโฃ Closures Preview
Closures are built on lexical scope.
Consider:
Output:
The returned function continues to access "count" even after "createCounter()" has finished executing.
๐ Double Tap โค๏ธ For More
โญ 1๏ธโฃ5๏ธโฃ What Is an Execution Context?
When JavaScript runs code, it creates an execution context.
An execution context is the environment in which JavaScript evaluates and executes code.
At a high level, there are different kinds of execution contexts.
The most important ones initially are:
โข Global Execution Context: Created when your JavaScript program begins executing.
โข Function Execution Context: Created whenever a function is called.
For example:
const name = "Rahul";
function greet() {
const message = "Hello";
console.log(message);
}
greet();
Conceptually:
Global Execution Context
โ
greet() called
โ
Function Execution Context
1๏ธโฃ6๏ธโฃ Creation Phase and Execution Phase
A simplified mental model is that JavaScript prepares an execution context before executing its statements.
During setup, JavaScript determines things such as:
โข Variable bindings
โข Function declarations
โข Lexical environments
Then JavaScript executes the code.
For example:
var age = 25;
function greet() {
console.log("Hello");
}
During the setup process, JavaScript prepares the relevant bindings.
Then execution proceeds through the statements.
This helps explain why function declarations and "var" behave differently from "let" and "const".
1๏ธโฃ7๏ธโฃ Execution Context Stack
JavaScript uses a call stack to keep track of active function execution.
Example:
function first() {
second();
}
function second() {
third();
}
function third() {
console.log("Hello");
}
first();The execution roughly looks like:
third()
โ
second()
โ
first()
โ
Global
When "third()" finishes:
third() removedThen:
second() finishesThen:
first() finishesEventually the stack becomes empty.
โญ 1๏ธโฃ8๏ธโฃ Call Stack
The call stack follows:
LIFO (Last In, First Out)
For:
function first() {
second();
}
function second() {
console.log("Hello");
}
first();The stack conceptually becomes:
1. Global
2. first()
3. second()
Then:
second() removedfirst() removedGlobal continues
Understanding the call stack becomes very important when we later study:
โข Callbacks
โข Asynchronous JavaScript
โข Promises
โข Event loop
โข Stack overflow
โญ 1๏ธโฃ9๏ธโฃ Scope vs Execution Context
These concepts are related but not identical.
โข Scope answers: "Where can this variable be accessed?"
โข Execution context answers more broadly: "What environment is JavaScript using while executing this code?"
For example:
const name = "Rahul";
function greet() {
const message = "Hello";
console.log(name);
console.log(message);
}
Scope determines which variables are accessible.
Execution context represents the environment created when "greet()" is actually executed.
โญ 2๏ธโฃ0๏ธโฃ Closures Preview
Closures are built on lexical scope.
Consider:
function createCounter() {
let count = 0;
return function () {
count++;
return count;
};
}
const counter = createCounter();
console.log(counter());
console.log(counter());
console.log(counter());Output:
1
2
3
The returned function continues to access "count" even after "createCounter()" has finished executing.
๐ Double Tap โค๏ธ For More
โค13