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 someVar; | |
if(someVar) { | |
// this if statement won't execute, as someVar hasn't been defined | |
} |
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
// here I just copied a list of nouns off the web. | |
// 'words' is an array of words because I created a string, then split | |
// it, like this: "my words".split(" "), which splits that string on the | |
// spaces. | |
words = "advice anger answer apple arithmetic badge basket basketball battle beast beetle beggar brain branch bubble bucket cactus cannon cattle celery cellar cloth coach coast crate cream daughter donkey drug earthquake feast fifth finger flock frame furniture geese ghost giraffe governor honey hope hydrant icicle income island jeans judge lace lamp lettuce marble month north ocean patch plane playground poison riddle rifle scale seashore sheet sidewalk skate slave sleet smoke stage station thrill throat throne title toothbrush turkey underwear vacation vegetable visitor voyage year".split(" "); | |
// syllables will be an array of three letter chunks generated by splitting | |
// up the words in our previous array. Note that I used the shorthand form | |
// of creating an array (also called an array literal). |
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
if(typeof someUndeclaredVariable == "undefined") { | |
// the if statement evaluates correctly-- no errors are thrown! | |
} |
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 myVar = true; // some random boolean variable set to true | |
var undefined = true; // here we "accidentally" defined undefined | |
if(myVar == undefined) { | |
// uh oh, this if statement evaluates to true! | |
} |
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
if(myVar == undefined) { | |
// var is undefined, oh noes! | |
} |
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
if(someUndeclaredVar) { | |
// curses, foiled again! This code throws an error as well. | |
} |
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 myString = "Hello, world!"; | |
alert(myString.substr(-6, 5)); | |
>> "world" |
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 someVar; | |
if(typeof someVar == "undefined") { | |
// evaluates to true, as expected | |
} |
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 string1 = "Hello "; | |
var string2 = "world!"; | |
var myStringArray = [string1, string2]; | |
myStringArray.join(""); | |
>> "Hello world!"; |
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
["Hello ", "world!"].join(""); | |
>> "Hello world!" |