Created
September 10, 2019 17:16
-
-
Save ryanknutson/4dfbd1c905abd7d370348697a12353b8 to your computer and use it in GitHub Desktop.
Useful Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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