This repository contains comprehensive notes and examples for JavaScript interview preparation, covering key concepts and common interview questions.
interview_questions/
├── variableShadowing.js # Examples of variable shadowing
├── higherOrderFunction.js # Higher order functions and callbacks
├── pureFunction.js # Pure vs impure functions
└── thiskeyword.js # Understanding 'this' keyword
- Definition: When a variable in a lower scope has the same name as a variable in a higher scope
- Examples showing different scopes (global, function, block)
- Best practices and common pitfalls
- Functions that take other functions as arguments
- Functions that return other functions
- Callback functions
- Common use cases and examples
- Characteristics of pure functions
- Side effects and their impact
- Examples of pure vs impure functions
- Advantages and disadvantages
- Different contexts of 'this'
- Regular functions vs arrow functions
- Constructor functions
- Event handlers
- call(), apply(), and bind()
- Clone the repository
- Navigate to the
interview_questions
directory - Open any
.js
file to view examples and explanations - Run the examples using Node.js or in browser console
# Using Node.js
node interview_questions/variableShadowing.js
node interview_questions/higherOrderFunction.js
node interview_questions/pureFunction.js
node interview_questions/thiskeyword.js
let x = 10; // Global scope
function myFunction() {
let x = 20; // Function scope
console.log(x); // 20
}
function greet(name, callback) {
console.log(`Hello, ${name}!`);
callback();
}
// Pure
function add(a, b) {
return a + b;
}
// Impure
let counter = 0;
function increment() {
counter++;
return counter;
}
const person = {
name: "John",
greet: function() {
console.log(`Hello, ${this.name}`);
}
};
-
Variable Shadowing
- Understand scope hierarchy
- Be aware of naming conflicts
- Know when shadowing might cause issues
-
Higher Order Functions
- Explain the concept clearly
- Provide real-world examples
- Understand callback patterns
-
Pure Functions
- Explain side effects
- Discuss benefits and trade-offs
- Provide practical examples
-
this Keyword
- Know different contexts
- Understand arrow functions
- Be familiar with binding methods
Feel free to contribute by:
- Adding more examples
- Improving explanations
- Adding new topics
- Fixing any errors
This project is open source and available under the MIT License.