Skip to content

www.leonenkov.ru

Comprehensive notes of a lifelong learner

  • Home
  • Author

JavaScript Tricks

Simple repeat function implementation in JS

24.01.202126.01.2021 ~ Roman
1
const repeat = (func, times) => [...Array(times).keys()].map(func);
 …

Swapping 2 JS variables’ values in one line

24.01.202122.05.2024 ~ Roman
1
2
3
let a = 10, b = 20;
[a, b] = [b, a];
console.log(a, b); // => 20, 10

Handy JS in operator

24.01.202126.01.2021 ~ Roman

The ‘in’ operator can help to check if an Array contains specified index or an Object contains a specified key …

Conditionally add a key to a JS Object or Array

01.01.202124.01.2021 ~ Roman
Conditionally add a key to an object: …

Remove a key from a JS Object using Spread operator

24.11.202024.01.2021 ~ Roman
Remove a key from an object with spread operator …

Nice tricks with Switch operator in JavaScript

17.09.201924.01.2021 ~ Roman
Evaluating expressions inside Switch statement …