https://hackernoon.com/js-var-let-or-const-67e51dbb716f
var x =5; // "declaration and assignment; a.k.a. initialization"
x=4; // "re-assignment"
Variables declared with "const" cannot be reassigned.
The following won't work because const y, assigned to 10, is being reassigned:
const y = 10;
y=5
The following will work, because const z, assigned to [1,2,3], is not being reassigned; the array it's pointing to ie being modified.
const z = [1,2,3];
z[0] = 3; // z is now [3,2,3]
Joe-approved comparison table:
Functions
Traditional Way (Factorial):
function factorial(x) {
if (x <=1 ) {return(1)}
else {return(x*factorial(x-1))}
}
ES6 Way: // Good practice to use "const" whenever possible
const fac = (x) => ( (x<=1) ? 1 : x *fac(x-1) )
or
const factorial = (x) => { return (x<=1) ? 1 : x *fac(x-1)}
Decrement:
for(n=100;n>0;n--) {console.log(n)}
Increment:
for(i=0;i<100;i++) {console.log(i)}
Evens and Odds:
for(i=0; i<=10;i+=2) {console.log(i)}
Named Parameters and Default Function Values: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/default_parameters
Code Snippets; Adding Breakpoints for Debugging
Config for Linting and Syntax Highlighting:
** No I2W next week (March 6, 2019) **, so practice coding interactively. Will begin building projects the week of March 13th.
https://codesignal.com https://codewars.com https://codecademy.com https://freecodecamp.org