Skip to content

Instantly share code, notes, and snippets.

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*.
}
myArray.forEach(function(element, index, array) {
console.log(element); // element is the current element in the array
console.log(index); // index is the position of that element in the array
console.log(array); // this is the array the forEach loop was called on
});
myArray.forEach(function(element, index, array) {
console.log(element); // element is the current element in the array
console.log(index); // index is the position of that element in the array
console.log(array); // this is the array the forEach loop was called on
});
while(true) {
// statement
if(condition == false) {
break;
}
}
do {
// statement
} while (false);
do {
statement;
} while (condition);
do {
statement;
} while (condition);
while(condition) {
// do something
}
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red" />
</svg>
// get the element we want
var myElement = document.getElementById("myElement");
// get its inner HTML and put it in an array
var myInnerHTML = [myElement.innerHTML];
for(var i = 0; i < 10; i++) {
// add a string to the end of the myInnerHTML array
myInnerHTML.push("some value");
}