Not delaying the execution of scripts
<head> section of your HTML document, the script will potentially start before any
There are several possible ways to solve this problem. The first solution is the simplest: placing all your scripts at the very end of the document, just before the closing
</body> tag. This guarantees that the script will execute after the
body content has loaded… but you should read the last point in this list for an important exception.
tokenOne is a different variable from
TokenOne. Scripts often break because you are trying to test or set the value of a variable that does not exist.
Confusing Concatenation & Addition
+ symbol to achieve their ends. It’s important to remember what you are joining together, how and why, and anticipate the result, in order to avoid errors:
In the console:
console.log(10 + 12); > 22 console.log(10+"2"); > “102” // note that this is a string, not a numeral token = 2; console.log(10 + token) > 12 token = "Two"; console.log(10 + token); > “10Two”
Confusing single and double quotes
console.log('Two'); > Two console.log("Two's"); > Two's console.log('Two's'); // result is an error
Confusing the DOM with data
Photograph by Vincent Moschetti, used under a Creative Commons Attribution-NonCommercial-NoDerivs 2.0 Generic license
Enjoy this piece? I invite you to follow me at twitter.com/dudleystorey to learn more.