Skip to content

Instantly share code, notes, and snippets.

@charmainetham
Created May 31, 2016 11:58
Show Gist options
  • Save charmainetham/6413e4b58c265bce7143bd193595aab0 to your computer and use it in GitHub Desktop.
Save charmainetham/6413e4b58c265bce7143bd193595aab0 to your computer and use it in GitHub Desktop.
Debugging exercises
//Why is this broken?
var mySuperAwesomeVariableName = "Ted Mosby";
mySuperAwesomeVariableName = "BATMAN!";
console.log(mySuperAwesomeVariableName);
//line breaks are interpreted as line-ending semicolons.
//Even in a string,if you include a hard line break in between quotes you’ll get a parse error (unterminated string).
//backslashes are the way to go
var bad = '<ul id="myId">\
<li>some text</li>\
<li>more text</li>\
</ul>';
// Why does this fail?
// with '=' we are reassigning a when we want to compare the valies
var a = 0;
if (a === 1) {
console.log("I Shouldn't be in here!");
} else {
console.log("I Should be in here!");
}
// the if condition does not meet the strict condition
var myVar = 5;
if(myVar == '5')
{
alert("If Alert");
}
switch(myVar)
{
case 5:
alert("Switch Alert");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment