Created
July 17, 2012 17:52
-
-
Save celeron55/3130819 to your computer and use it in GitHub Desktop.
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
// Assignment: | |
var number = 42 | |
var opposite = true | |
// Conditions: | |
number = opposite ? -42 : number | |
// Functions: | |
var square = function(x){ return x * x } | |
// Arrays: | |
var list = [1, 2, 3, 4, 5] | |
// Objects: | |
var math = { | |
root: Math.sqrt, | |
square: square, | |
cube: function(x){ return x * square(x) } | |
}; | |
// Splats: | |
// This is so rare nobody cares of a few lines of code. | |
var race = function() { | |
var winner = arguments[0] | |
var runners = arguments.length >= 2 ? [].slice.call(arguments, 1) : [] | |
return print(winner, runners) | |
}; | |
// Existence: Oh hell, why not just define the variable so you can use it like a variable? | |
if(typeof elvis !== "undefined" && elvis !== null) alert("I knew it!") | |
// Array comprehensions (JS 1.6): | |
var cubes = list.map(function(x){ return math.cube(x) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment