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 bob = { | |
name: "Bob", | |
age: 32 | |
}; | |
var bill = $.extend(true, {}, bob); | |
bill.name = "Bill"; | |
console.log(bob); | |
console.log(bill); |
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 bob = { | |
name: "Bob", | |
age: 32 | |
}; | |
var bill = (JSON.parse(JSON.stringify(bob))); | |
bill.name = "Bill"; | |
console.log(bob); | |
console.log(bill); |
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
// recursive function to clone an object. If a non object parameter | |
// is passed in, that parameter is returned and no recursion occurs. | |
function cloneObject(obj) { | |
if (obj === null || typeof obj !== 'object') { | |
return obj; | |
} | |
var temp = obj.constructor(); // give temp the original obj's constructor | |
for (var key in obj) { |
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
myString = (myString == "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
var myString = "true"; | |
if(myString == "true") { | |
// this evaluates to true correctly, myString is true | |
} | |
if(myString == "false") { | |
// this evaluates to false, also correct, since myString doesn't equal false. | |
} |
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 = "true"; | |
if(Boolean(myString)) { | |
// very good, this if statement evaluates to true correctly! | |
} | |
if(!Boolean(myString)) { | |
// and this one evaluates to false! Our problems are solved! | |
} |
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 = true; | |
if (myString) { | |
// this should evaluate to true because myString = "true", and it does. Good! | |
} | |
if (!myString) { | |
// uh oh! This evaluates to true as well. Why? Because if(!myString) | |
// is checking to see if myString *exists*, not if it's *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
myString = (myString == "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
var myString = "true"; | |
if(myString == "true") { | |
// this evaluates to true correctly, myString is true | |
} | |
if(myString == "false") { | |
// this evaluates to false, also correct, since myString doesn't equal false. | |
} |
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 = "true"; | |
if(Boolean(myString)) { | |
// very good, this if statement evaluates to true correctly! | |
} | |
if(!Boolean(myString)) { | |
// and this one evaluates to false! Our problems are solved! | |
} |