Understanding Lexical Environment in JavaScript

🚀 Mock Interview Learning – Lexical Environment in JavaScript Today in my mock interview, I was asked: 👉 “What is Lexical Environment?” Here’s how I understood it: A Lexical Environment is the environment where variables and functions are accessible based on their position in the source code. In JavaScript, scope is determined by where functions and variables are written, not where they are called. Example: function outer() { let a = 10; function inner() { console.log(a); // inner can access 'a' } inner(); } Because inner() is written inside outer(), it has access to outer’s variables. This is called lexical scoping. 💡 Key Concepts Related: Scope Scope Chain Closures Mock interviews really help in identifying knowledge gaps and improving confidence. Learning step by step. Improving every day. 🚀 #JavaScript #FrontendDevelopment #WebDevelopment #InterviewPreparation #LearningInPublic

To view or add a comment, sign in

Explore content categories