JavaScriptのベストプラクティス大会 jsEdu
![](https://s.togetter.com/static/web/img/placeholder.gif)
to ensure your function *actually* returns a Boolean, use the double-bang (e.g., return !!name;) #jsEdu
2010-10-13 01:44:32![](https://s.togetter.com/static/web/img/placeholder.gif)
Include scripts dynamic, inject or use defer/async in <script tags to prevent JS files from blocking the browser rendering the page. #jsEdu
2010-10-13 01:45:40![](https://s.togetter.com/static/web/img/placeholder.gif)
Making IE html5 compatible, html5shim - http://goo.gl/AYbS #jsEdu
2010-10-13 01:51:56![](https://s.togetter.com/static/web/img/placeholder.gif)
Javascript tip - Avoid 'eval' - If it exists in your page, there is almost always a more correct way to accomplish what you are doing #jsEdu
2010-10-13 01:52:33![](https://s.togetter.com/static/web/img/placeholder.gif)
shortcut notations keep your code snappy and easier to read once you got used to it #jsEdu
2010-10-13 01:52:59![](https://s.togetter.com/static/web/img/placeholder.gif)
want better js? write js unit tests. tons of great tools out there. Start by looking at how your favorite framework tests itself #jsEdu
2010-10-13 01:53:25![](https://s.togetter.com/static/web/img/placeholder.gif)
Reference form and their elements correctly: document.forms["formname"].elements["inputname"], not document.formname.inputname #jsEdu
2010-10-13 01:55:00![](https://s.togetter.com/static/web/img/placeholder.gif)
example: `(!variable)` will be true for null, false, undefined, '' and 0. Useful and dangerous. #jsEdu #javascript
2010-10-13 01:55:25![](https://s.togetter.com/static/web/img/placeholder.gif)
#javascript formula for determining number of days in a month: var numdays = 32 - new Date([year], [month], 32).getDate(); #jsEdu
2010-10-13 01:57:04![](https://s.togetter.com/static/web/img/placeholder.gif)
Always use option objects for optional arguments instead of loose arguments when calling a function {loop: false, duration: 200} #jsEdu
2010-10-13 01:57:09![](https://s.togetter.com/static/web/img/placeholder.gif)
Always better to group variable declarations like var a, b; if you need to assign a value, check the scope! #jsEdu
2010-10-13 01:59:37![](https://s.togetter.com/static/web/img/placeholder.gif)
Use var arr=['a','multiline','paragraph']; arr.push('another line'); and then arr.join('\n'); or arr.join('<br />'); to combine them #jsEdu
2010-10-13 02:00:41![](https://s.togetter.com/static/web/img/placeholder.gif)
Use a bitwise operator -- ~~ -- instead parseInt(number, 10) to parse a float number to int. #jsEdu
2010-10-13 02:03:28![](https://s.togetter.com/static/web/img/placeholder.gif)
function plop(super){alert(super);} Works fine in FF but will throw an error in Safari/Chrome. Because "super" is a reserved word • #jsEdu
2010-10-13 02:08:03![](https://s.togetter.com/static/web/img/placeholder.gif)
Use the typeof operator to check if a variable has been declared. (typeof Var === "undefined") rather than (!Var) #jsEdu
2010-10-13 02:09:11![](https://s.togetter.com/static/web/img/placeholder.gif)
It's cool post @voodootikigod! RT Put the http://promotejs.com badge on your blog #jsEdu
2010-10-13 02:18:47![](https://s.togetter.com/static/web/img/placeholder.gif)
Use call and apply to invoke functions in the context of specific objects. #jsEdu
2010-10-13 02:21:39![](https://s.togetter.com/static/web/img/placeholder.gif)
Fair chance using ternary instead of IF/ELSE: (Math.random()*100 > 50 ? alert("fair chance") : false ) #jsEdu
2010-10-13 02:29:33![](https://s.togetter.com/static/web/img/placeholder.gif)
Don't interfere with the user experience and disable the browser back button unless you have to in a form. #jsEdu
2010-10-13 02:31:07![](https://s.togetter.com/static/web/img/placeholder.gif)
name your variables in a way that makes sense to somebody reading your code. #jsEdu
2010-10-13 02:32:31![](https://s.togetter.com/static/web/img/placeholder.gif)
null is a special value that means "no value", undefined means that the variable has not been declared #jsEdu
2010-10-13 02:36:19![](https://s.togetter.com/static/web/img/placeholder.gif)
test often. using alert('whatever here'); helps you know where in your code things are at when it fails. #jsEdu
2010-10-13 02:40:10![](https://s.togetter.com/static/web/img/placeholder.gif)
Always use the var statement to declare a variable #jsEdu
2010-10-13 02:42:21