Block Binding in ES6

What is Binding?

VAR Binding: Confusion

function getValue(condition) {

if (condition) {
var value = "blue";

// other code

return value;
} else {

// value exists here with a value of undefined

return null;
}

// value exists here with a value of undefined
}

Loops and block-level declarations

for (var i = 0; i < 10; i++)
{
// code goes here
}
console.log(i); // still works!
for (let i = 0; i < 10; i++)
{
}console.log(i); // error!

Loops and ‘const’ declarations

for (const i = 0; i < 5; i++)
{
// will only run one time before error
}
var car = {
make: 'Honda',
model: 'Fit'
};
for (const key in car){
console.log(key); // totally fine
}

Summary

2. AsyncFunction

async function f() {
return 1;
}
async function f() {
return 1;
}

f().then(alert); // 1
async function f() {
return Promise.resolve(1);
}

f().then(alert); // 1

3. awaitFunction

// works only inside async functions
let value = await promise;
async function f() {

let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});

let result = await promise; // wait until the promise resolves (*)

alert(result); // "done!"
}

f();

4.typeof()

for Example :

5.Equality (==)

for Example :

console.log(1 == 1);
// expected output: true
console.log('hello' == 'hello');
// expected output: true
console.log('1' == 1);
// expected output: true
console.log(0 == false);
// expected output: true

6.Spread Operator

for Example :

const inputValue = [...value];

7. Arrow functions

for Example :

const multify = (x) => {return (x*x);};
console.log(multify(9));
------------------------
const nums = [
'100',
'2003',
'30004',
'4005'
];
console.log(nums.map(num => num.length));
//expected output:Array [3, 4, 5, 4]

8. Anonymous Functions

let show = ()=> {     
console.log('Anonymous function');
};
show();

Summary

  • Anonymous functions are functions without names.
  • Anonymous functions can be used as an argument to other functions or as an immediately invoked function execution.

9.JavaScript prototype

console.log(Object);
console.log(Object.prototype);

10. What is https

HyperText Transfer Protocol Secure

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store