Skip to content

Instantly share code, notes, and snippets.

@ryanknutson
Created September 10, 2019 17:16
Show Gist options
  • Save ryanknutson/4dfbd1c905abd7d370348697a12353b8 to your computer and use it in GitHub Desktop.
Save ryanknutson/4dfbd1c905abd7d370348697a12353b8 to your computer and use it in GitHub Desktop.
Useful Javascript
// Create a range
[...Array(5).keys()];
// [0, 1, 2, 3, 4]
// Using let for block scope
var a = 'car';
{
let a = 5;
console.log(a) // 5
}
console.log(a) // car
// arrow functions
var foo = function( a, b ) {
return a * b;
}
// can be written as
let bar = ( a, b ) => a * b;
// swap variables without temp
let a = 1;
let b = 2;
[b, a] = [a, b];
// for of loop
for (let x of list) {
// do something with x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment