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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="pony-list-wrapper"></div> | |
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 thing = 'bat'; | |
var sing = function() { | |
// Bên trong ‘sing’ có thể thấy biến line | |
var line = 'Twinkle, twinkle, little ' + thing; | |
console.log(line); | |
}; | |
sing(); | |
// Twinkle, twinkle, little bat |
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 outer = function() { | |
var outerVar = 'Hatter'; | |
var inner = function() { | |
// Hàm trong ‘inner’ có thể thấy biến outerVar | |
console.log(outerVar); | |
// Hatter | |
var innerVar = 'Dormouse'; | |
// 🌳🌳🦍🌄 phạm vi của innerVar là trong hàm inner, bên ngoài không thể thấy | |
} |
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 showArgs = function(a, b) { | |
console.log(arguments); | |
} | |
showArgs('Tweedledee', 'Tweedledum'); | |
//=> { '0': 'Tweedledee', '1': 'Tweedledum' } (🌟) |
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
// đối số ít hơn tham số | |
showArgs('less'); | |
//=> { 0: "less" } | |
// đối số nhiều hơn tham số | |
showArgs('a', 'l', 'i', 'c', 'e'); | |
//=> { '0': 'a', '1': 'l', '2': 'i', '3': 'c', '4': 'e' } |
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 argsLen = function() { | |
console.log(arguments.length); | |
} | |
argsLen('a', 'l', 'i', 'c', 'e'); | |
//=> 5 |
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 twinkleTwinkle(thing) { | |
console.log('Twinkle, twinkle, little ' + thing); | |
} | |
twinkleTwinkle('bat'); | |
//=> Twinkle, twinkle, little bat |
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
twinkleTwinkle.call(null, 'star'); | |
//=> Twinkle, twinkle, little star |
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
twinkleTwinkle.apply(null, ['bat']); | |
//=> Twinkle, twinkle, little bat |
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 numbers = [1, 2, 3]; | |
var doubledArray = map(function(x) { return x * 2}, numbers); | |
console.log(doubledArray); | |
//=> [ 2, 4, 6 ] |