Skip to content

Instantly share code, notes, and snippets.

@vikneshwar
Last active June 24, 2021 13:30
Show Gist options
  • Save vikneshwar/45d24e8b99dbdb088de35bd199d60a2a to your computer and use it in GitHub Desktop.
Save vikneshwar/45d24e8b99dbdb088de35bd199d60a2a to your computer and use it in GitHub Desktop.
//pure functions
//given a input will always return a same output
//will not cause side effects
const add = (a, b) => a + b;
//impure function 1
const magicLetter = "*";
const createMagicPhrase = (phrase) => `${magicLetter}abra${phrase}`;
//impure function 2
const fetchLoginToken = externalAPI.getUserToken;
//Closure
//Ex:
//Hoisting
//Ex:
console.log(x); // undefined
var x = 2;
console.log(x); //2
//let and const are hoisted but not assigned a value so will throw error
//Ex:
var x = 10;
{
console.log(x); //throws undefined error
let x = 20;
}
//IIFE
// Why IIFE
var x = 10;
console.log(x);
(function () {
console.log(x);
var x = 2;
console.log(x);
})();
// .call .apply .bind
// ES6 Features
// Node Architecture
if (new Boolean(false)) {
console.log("TEST");
}
//function hoisting
foo();
var foo = function () {
console.log("TEST");
};
//Promises
let data = {
name: "viknesh",
};
let data_1 = data;
data_1.name = "xyz";
console.log(data);
//first class functions
// node advantage vs disadvantage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment