Javascript Tip and Triks

883 views

Published on

Published in: Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
883
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Javascript Tip and Triks

  1. 1. JavascriptTips and Tricks<br />@EBvi<br />
  2. 2. Declaring a Function<br />function foo() {}<br />var bar = function() {}<br />The difference is that foo is defined at parse-time for a script block, whereas bar is defined at run-time.<br />
  3. 3. Anonymous function<br />(function (){})<br />
  4. 4. Different ways of calling functions<br />alert (“Hello, World!");<br />(alert) (“Hello, World!");<br />(function(x,y,z) {return (x+y+z)}) (1, 2, 3); <br />
  5. 5. Using functional concepts<br />Functions need not have names all the time.<br />Functions can be assigned to variables like other values.<br />A function expression can be written and enclosed in parentheses for application later.<br />Functions can be passed as arguments to other functions.<br />
  6. 6. JS does not have block scope.<br />varx = 1; <br />{ <br />  var x = 2; <br />} <br />alert(x); // outputs 2<br />Block statements do not introduce a scope.<br />
  7. 7. {}<br />{} is object notation in JavaScript.<br />An extremely terse and flexible way to pass information.<br />
  8. 8. ;<br />At the end of the last script without a ; on the end. If you have a ; at the start on yours, it's safe.<br />
  9. 9. ++ and --<br />The ++ (increment) and -- (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces. There is a plusplus option that prohibits the use of these operators.<br />- Douglas Crockford<br />
  10. 10. use === and !== instead of == and !=<br />== is not transitive. If you use === it would give false for all of these statements as expected.<br />
  11. 11. Reference<br />http://stackoverflow.com/questions<br />http://en.wikipedia.org/wiki/Unobtrusive_JavaScript<br />http://javascript.crockford.com<br />http://www.ibm.com/developerworks/library/wa-javascript.html<br />https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Statements<br />JavaScript: The Good Parts<br />

×