Tuesday, March 19, 2013

Javascript functions and difference



The two ways to declare a java script function:
var functionOne = function() {
    // Some code
};
function functionTwo() {
    // Some code
}


The difference is that functionTwo is defined at parse-time for a script block, whereas functionOneis defined at run-time. For example:
<script>
  // Error
  functionOne();

  var functionOne = function() {
  }
</script>

<script>
  // No error
  functionTwo();

  function functionTwo() {
  }
</script>




No comments:

Post a Comment