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
var | |
// JavaScript is liberal about white space! | |
firstname, | |
// JavaScript is so liberal about white space!! | |
lastname, | |
// JavaScript is such liberal about white space!!! | |
// Oh my god! | |
email; |
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
class BaseChanger: | |
BASE = 10 | |
NEW_BASE = None | |
MINUS_SIGN = False | |
def __init__(self, n, new_base, n_base=BASE): | |
self.NEW_BASE = new_base | |
if n_base: | |
self.BASE = n_base |
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
// Function Statement | |
greet(); // hoisting | |
function greet(){ | |
console.log('hi'); | |
}; | |
// FUNCTION EXPRESSION (ANONYMOUS) | |
anonymousGreet(); // undefined is not a function |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
// Global variable | |
var greeting = 'Hola'; | |
// Immediately Invoked Function Expressions | |
(function(global, name) { | |
var greeting = 'Hello'; | |
consoel.log(global.greeting); // 'Hola' | |
console.log(greeting + ' ' + name); // 'Hello John' | |
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
function greet(whattosay) { | |
return function(name) { | |
consoel.log(whattosay + ' ' + name); // include variable whattosay by scope chain | |
} | |
} | |
greet('Hello')('John'); // 'Hello John' |
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
function buildFunctions() { | |
var arr = []; | |
for(var i=0; i<3; i++) { | |
// add three function to arr | |
arr.push( | |
function() { | |
console.log(i); |
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
function makeGreeting(language) { | |
return function(name){ | |
if(language == 'en') console.log('Hello' + name); | |
if(language == 'es') console.log('Hola' + name); | |
} | |
} | |
var greetEnglish = makeGreeting('en'); | |
greetEnglish('John'); // Hello John |
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
function sayHiLater() { | |
var greeting = 'Hi'; | |
// uses first-class function and create a function object on the flay by function expressions | |
setTimeout(function() { | |
console.log(greeting); // 30 sec later, it still have access to greeting variable | |
}, 30000); | |
} |
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
function callLater(callback) { | |
console.log('Some work...'); | |
callback(); | |
} | |
callLater(function() { |