the code

this is my 5 month journey to crack the code

DAY 1
ARROW FUNCTION ES6;
var a = function (x,y) {
return x + y;
}
//equal to (return keyword not needed in absence of curliefries)
var b = (x, y) => x + y;
//example
var squared = x => x*x;
//example
var deliveryBoy = {
name: “John”,
handleMessage: function (message, handler) {
handler (message);
},
receive: function () {
var this = that;
this.handleMessage (“Hello,”, function (message){
that.name; // get actual name
console.log (message + that.name);
})
}
}
deliveryBoy.receive ();

//using fat arrow being
var deliveryBoy = {
name:”John”,
handleMessage: function (message, handler){
handler (message);
},
receive: function () {
this.handleMessage (“Hello,”, message => console.log
(message + this.name) )
}
}
deliveryBoy.receive ();

*** LET KEYWORD ES6
ES5:
var can be reassigned unless latter vars are locked in a function scope
ES6:
let allows block scoping to be separate entities

DAY 2
DEFAULT VALUES FOR FUNCTION PARAMETERS ES6
//when logged out, can run default arguements as assigned, overridden, or as undefined if no arguement assigned
//can also invoke functions as default arguements
//example
function greet (greeting, name = “John”){
console.log(greeting + “,” + name);
}
greet (“Hello”, “Bill”); // Bill overrides John
//returns
Hello, Bill

//example 1
function receive(complete){
complete ();
}
receive (function ( ) {
console.log(“complete”);
});

//example 2 using a default function
function receive (complete = function ( ) {
console.log (“complete”);
}) {
complete ( );
}
receive ( );
//example 3 assign as default function using fat arrow
function receive(complete = ( ) => console.log
(“complete”)) {
complete ( );
}
receive ( );
//example 4 fat arrow centric
let receive = (complete = ( ) => console.log
(“complete”) ) = complete ( )
receive ( )

DAY 3
CONST DECLARATION ES6 (ES2015)
//use all cap when assigning a variable to indicate it should not be reassigned
//example
var VALUE = ‘hello world’;
VALUE = ‘foo bar’
console.log (‘value’:, VALUE);
//returns value: foo bar (the last assigned value)
//const declares read-only variable, where properties of such variables may be reassigned within their type
//example
const VALUE = { };
VALUE.foo = ‘bar’;
console.log (‘value: ‘, VALUE);
//returns
value: {foo: ‘bar’}
//cont declarations adhere to clock scope (space between curliefries)

DAY 4
SHORTHAND PROPERTIES ES6
//backwards destructuring with shorthand syntax to push properties into an object
//example
let firstName = “John”;
let lastName = “Lindquist”;
let person = {firstName, lastName}
console.log(person);
//returns
{firstName: ‘John’, lastName: ‘Lindquist’)
let mascot = “Moose”;
let team = {person, mascot);
console.log(team);
//returns
{person: {firstName: ‘John’, lastName: ‘Lindquist’},
mascot: ‘Moose’}

OBJECT ENHANCEMENTS ES6
//example
var colour = “red”;
var speed = 10;
function go ( ) {
console.log(“vroom”);
}
var car = {
colour,
speed,
go
};
console.log (car.colour);
console.log (car.speed);
car.go ( );
//alternatively
var colour = “red”;
var speed = 10;
var car = {
colour,
speed,
go ( ) {
console.log (“vroom”);
}
};
console.log (car.colour);
console.log (car.speed);
car.go ( );
//fun alternatives
var colour = “red”;
var speed = 10;
var car = {
colour,
speed,
[“go”]: function ( ) {
console.log (“vroom”);
}
};
console.log (car.colour);
console.log (car.speed);
car.go( );
//otherwise written as
var colour = “red”;
var speed = 10;
var drive = “go”;
var car = {
colour,
speed,
[drive]: function ( ) {
console.log(“vroom”);
}
};
console.log (car.colour);
console.log (car.speed);
car.go ( );

DAY 5
SPREAD OPERATOR ES
//takes an array and “spreads” out into individual items (think playing cards), allows elements to be easily pushed into other arrays
//example
console.log([1, 2, 3 ]);
//returns
[1, 2, 3 ]
//whereas
console.log(…[1, 2, 3]);
//returns
1, 2, 3
//push example
let first = [1, 2, 3];
let second = [4, 5, 6];
first.push(second);
console.log(first);
//returns
[1, 2, 3, [4, 5, 6] ]
//whereas
let first =

%d bloggers like this: