Understanding Destructuring in JavaScript with ES6

🎯 Today in my mock interview, I was asked: What is Destructuring in JavaScript? Here’s how I answered: Destructuring was introduced in ES6. It is a way of unpacking values from arrays or properties from objects into separate variables. 🔹 Array Destructuring uses square brackets [] 🔹 Object Destructuring uses curly braces {} Example: // Array Destructuring const numbers = [1, 2, 3]; const [a, b] = numbers; // Object Destructuring const user = { name: "Aditya", age: 24 }; const { name, age } = user; In object destructuring, the variable name should match the object key (unless we rename it). Mock interviews are helping me improve daily 🚀 Small improvements every day. #javascript #frontenddeveloper #reactjs #webdevelopment #interviewprep

in which platform you are giving mock interview

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories