• Save
Javascript Tip and Triks
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
754
On Slideshare
745
From Embeds
9
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
2

Embeds 9

http://www.scoop.it 9

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