JavaScript Fundamentals Before Learning React
1. Variable Scoping and Assignment
Variable Scoping refers to the accessibility of variables within different parts of your code.
In JavaScript, scope is determined by the location where you declare a variable.
Global Scope: Variables declared outside any function or block have global scope and can be
accessed anywhere in the code.
Function Scope: Variables declared within a function are only accessible inside that function.
Block Scope: Variables declared with let or const inside a block {} are only accessible within that
block.
Assignment is the process of setting a value to a variable using the = operator.
var globalVar = 'I am global';
function scopeTest() {
var functionVar = 'I am local to the function';
console.log(globalVar); // Accessible
console.log(functionVar); // Accessible
console.log(globalVar); // Accessible
console.log(functionVar); // Uncaught ReferenceError
2. Destructuring
Destructuring allows you to unpack values from arrays or properties from objects into distinct
variables.
Array Destructuring
const [first, second] = [10, 20];
console.log(first); // 10
console.log(second); // 20
Object Destructuring
const person = { name: 'Alice', age: 25 };
const { name, age } = person;
console.log(name); // Alice
console.log(age); // 25
... (continued for each concept)