Sitemap
Bootcamp

From idea to product, one lesson at a time. To submit your story: https://tinyurl.com/bootspub1

Member-only story

5 Javascript trick you must know

3 min readApr 17, 2024

--

5 Javascript trick you must know

Okay, here are 5 tricks you can master to enhance your coding skills and productivity greatly. let’s get to it

Destructuring assignment

The destructuring assignment offers a concise method to extract values from arrays or objects and assign them to variables, thereby simplifying your code and enhancing readability. For arrays, bracket notation is used, while braces are employed for objects.

// Destructuring assignment
const[a,b, ...theRest] = [1,2,3,4,5,6,7];

console.log(a);
// Expected otput: 1

console.log(b);
// Expected otput: 2

console.log(theRest);
// Expected output: Array [3,4,5,6,7]

// Destructuring object
const {name, breed, ...details} = {name: 'Nimbus', age:'4', type:'cat', color:'orange'};

console.log(name);
// Expected otput: "Nimbus"

console.log(b);
// Expected otput: "4"

console.log(details.type);
// Expected output: cat

console.log(details.color);
// Expected output: orange

Spread Syntax

Spread syntax looks exactly like rest syntax. In a way, spread syntax is the opposite of rest syntax.

The spread syntax allows you to spread the elements of an array or the properties of an object into another array or object. This is particularly useful for tasks like making copies, merging objects, and passing multiple…

--

--

Bootcamp
Bootcamp

Published in Bootcamp

From idea to product, one lesson at a time. To submit your story: https://tinyurl.com/bootspub1

Shakir
Shakir

Written by Shakir

I do 3d and write code with a passion for game development and software, and 3d.

Responses (1)