Cheatography
https://cheatography.com
A basic how to cheat sheet for beginner and experienced JavaScript developers. Quickly refresh syntax and functions.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Basics
On Page Script |
|
< script type= "text/javascript"
> ... < /script> |
Include external JS file |
< script src= filename.js
>< /script> |
Delay - 1 second timeout |
setTimeout(function () { }, 1000); |
Functions |
function addNumbers(a, b) { return a + b; ; } x = addNumbers(1, 2); |
Edit DOM Element |
document. getElementById( "elementID"
).innerHTML = "Hello World!"
; |
Output |
console.log(a); document.write(a);
|
// write to the browser console
|
|
|
For Loop
bold
for (var i = 0; i < 10; i++) {
document.write(i + ": " + i*3 + "<br />");
}
var sum = 0;
for (var i = 0; i < a.length; i++) {
sum + = a[i];
} // parsing an array
html = "";
for (var i of custOrder) {
html += "<li>" + i + "</li>";
}
|
|
|
Loops
for (var i = 0; i < 10; i++) { document.write(i + ": " + i*3 + "<br />"); } var sum = 0; for (var i = 0; i < a.length; i++) { sum + = a[i]; } // parsing an array html = ""; for (var i of custOrder) { html += "<li>" + i + "</li>"; }
|
|