torsdag den 18. juni 2009

24 JavaScript Best Practices for Beginners


En hel JS julekalender ...
/Sik


24 reasons to be a beginner ...
/Sik



Quote

1. Use === Instead of ==

JavaScript utilizes two different kinds of equality operators: === | !== and == | != It is considered best practice to always use the former set when comparing.

"If two operands are of the same type and value, then === produces true and !== produces false." - JavaScript: The Good Parts

However, when working with == and !=, you'll run into issues when working with different types. In these cases, they'll try to coerce the values, unsuccessfully.

2. Eval = Bad

For those unfamiliar, the "eval" function gives us access to JavaScript's compiler. Essentially, we can execute a string's result by passing it as a parameter of "eval".

Not only will this decrease your script's performance substantially, but it also poses a huge security risk because it grants far too much power to the passed in text. Avoid it! [...]

Source: Net Tuts +


Read more: http://net.tutsplus.com/tutorials/javascript-ajax/24-javascript-best-practices-for-beginners/

Ingen kommentarer:

Send en kommentar