Your SlideShare is downloading. ×
Javascript Common Mistakes
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Javascript Common Mistakes

1,124
views

Published on

Javascript Common Mistakes

Javascript Common Mistakes

Published in: Technology

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,124
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. Javascript Common Mistakes
      Dongsu Jang <iolothebard at gmail.com>
      http://blog.iolo.pe.kr
    • 2. Unaware of:Async! Async! Async!
      var result1, result2, result3;
      $.ajax(..., success: function(data) { result1 = data; });
      $.ajax(..., success: function(data) { result2 = data; });
      result3 = result1 + result2;
      But, don’t do that: “async: false”
    • 3. Unaware of:this “this” is not the “this”
      function test(name, button) {
      this.name = name;
      button.onclick= function(event) {
      alert('hello, ' + this.name);
      };
      }
    • 4. Unaware of:“not of not” is not the not of “not”
      function test(foo) {
      alert(typeof(foo));
      alert(foo);
      if (foo) { alert('foo'); }
      if (!foo) { alert(‘!foo'); }
      if (!!foo) { alert('!!foo'); }
      }
    • 5. Misunderstaning0, null, false, undefined, NaN and “”
      function test(foo) {
      alert(typeof(foo));
      alert(foo);
      if (foo) { alert('foo'); }
      if (foo == null) { alert('foo == null'); }
      if (foo === null) { alert('foo === null'); }
      }
    • 6. Trying todeclaring block scope “var”s
      function test() {
      var foo = -1;
      for (varfoo = 0; foo < 10; foo++) { … }
      alert(foo);
      }
    • 7. Trying tooverload a function
      function test(foo) {
      alert('one arg');
      }
      function test(foo, bar) {
      alert('two args');
      }
      function test() {
      for (var i = 0; i < arguments.length; i++) {
      alert(arguments[i]);
      }
      }
    • 8. Using escape() instead of encodeURIComponent(), encodeURI()
      Checkout http://xkr.us/articles/javascript/encode-compare/
      Rule of thumb!
      use encodeURIComponent()
      use encodeURI() only if you know what it is
      forget escape()
    • 9. Unaware ofstring is not array-of-characters
      var str = “hello”;
      alert(str.charAt(2));
      alert(str[2]);
      Similarly, NodeList is not array-of-Nodestoo!
    • 10. Missing“radix” for parseInt()
      var sum = parseInt(num1.value) + parseInt(num2.value);
      alert(sum);
      parseInt('1234');
      parseInt('01234');
      parseInt('1234', 8);
      parseInt('01234', 10);
    • 11. Sorry…it’s a comma… just a trailing comma…
      var test = { 1, 2, 3, };
      out.print(“{“);
      for (int val: values) { out.print(i); out.print(“,”); }
      out.print(“}”);
    • 12. Using Vanilla JavaScript
      Checkout http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
      http://jquery.com/
      http://prototypejs.org/
      http://dojotoolkit.org/
      and so on…
    • 13. Testing in one browserand expecting it to work in another
      Checkout http://www.quirksmode.org/
    • 14. Not using jslint
      Checkout http://jslint.com/
    • 15. The most common mistake is“using JavaScript”
      Thanks you… ;)