This file contains hidden or 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 hidden or 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
// this case will cause automatic semicolon insertion | |
// and return wrong value when invoking this function | |
function getPerson() { | |
return | |
{ | |
name: 'Tony', | |
} | |
} |
This file contains hidden or 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; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |