JavaScript Day 18 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation
100 Days of JavaScript Interview Prep: A Beginner’s Journey


Welcome to Day 18–100 Days of JavaScript Interview Prep: A Beginner’s Journey
Embarking on a 100-day adventure focused on learning, practice, and growth sounds like an incredibly rewarding journey.
DAY 18 (April 9th, 2024) — ES6 Related Interview Questions ?
Question 1 — What is the Rest Parameter in ES6? How is it used in functions?
Answer —
- The rest parameter allows a function to accept an indefinite number of arguments as an array.
- It is denoted by three dots (
...) followed by the parameter name.
Example below how rest works
function f(a, b, ...theArgs) {
// …
}
function myDetails(name, employedId, ...manyMoreArgs) {
console.log("name", name);
console.log("employedId",employedId);
console.log("manyMoreArgs", manyMoreArgs);
}
myDetails("tom", "12313232", "123 street road", "01234", "40k", "Male");
Question 2 — Explain the concept of Destructuring Assignment in ES6 functions?
Answer —
- Destructuring assignment allows you to extract values from objects or arrays and assign them to variables in a concise way.
- It can be used with function parameters to extract specific values from objects or arrays passed as arguments.
/* Example 1 - Below are the way of desctructing
const [a, b] = array;
const [a, , b] = array;
*/
const x = [1, 2, 4, 5];
const [y, z,k] = x;
console.log(y); // 1
console.log(z); // 2
console.log(k); // 2
// example 2 - ({ a, b } = obj); // parentheses are required
function getUserInfo({ name, age }) { // Destructuring with name and age
console.log(`Name: ${name}, Age: ${age}`);
}
const user = { name: 'tom', age: 30 };
getUserInfo(user); // Output: "Name: Alice, Age: 30"

Note — Please also follow below article to try different ways of destructuring

Happy Coding and Stay Tuned :)
Kind is cool !!!
Share knowledge to gain knowledge !!!!
Be kind and treat people with respect !!
If you find my blog helpful, then please subscribe, Claps and follow to support :)
Cheers Kirti Kaushal





