#9 Locals are still a good idea - Lessons Learned While Reading "Effective Javascript"
Submitted by Jesper on March 20, 2013 - 22:34Variables declared inside of a function will automatically be made global unless it is prefixed with "var".
#8 Globals are still a bad idea - Lessons Learned While Reading "Effective Javascript"
Submitted by Jesper on March 19, 2013 - 23:31One of the first things you notice with JS is just how easy it is to pollute the global namespace. Obviously, you should avoid doing that. One little detail worth keeping in mind: Global variables are automatically attached to the global object and can be updated as such.
#7 Unicode - Lessons Learned While Reading "Effective Javascript"
Submitted by Jesper on March 18, 2013 - 19:23In JavaScript, strings consist of 16-bit code units (not code points). Characters that you wish to represent which are outside of the Base Multilingual Plane must be represented using surrogate pairs.
#6 Semicolons - Lessons Learned While Reading "Effective Javascript"
Submitted by Jesper on March 17, 2013 - 19:34In Javascript, semicolons are optional. However, for the sake of simplicity, it's best to include them. Furthermore, when always including semicolons, it's important to remember that the following statements may not have a newline before their arguments: (JS will implicitely insert a semicolon)
- ++
- --
- break
- continue
- return
- throw
#5 Operator Equals - Lessons Learned While Reading "Effective Javascript"
Submitted by Jesper on March 16, 2013 - 20:58In Javascript you have two equals operators: implicit coercion equals operator (==) and strict equality operator (===). The former will try to coerce different types and attempt equality checks, while the latter will only operate without any conversions.
Because of these properties, the "===" operator is prefered, as it's explicit nature yields less potentially tricky (buggy) code due to non-obvious conversions. (and helps with code readability)
#4 Primitives - Lessons Learned While Reading "Effective Javascript"
Submitted by Jesper on March 15, 2013 - 22:37Javascript has five primitives available:
- Booleans
- Null
- Numbers
- Strings
- Undefined
You can also implicitely coerce Object properties/methods from primitives: