Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


What is the difference between var functionName = function() {} and function functionName() {}

Jeson84Jeson84 USAMember Posts: 90
edited February 2014 in JavaScript

I came across two types of functions definitions in a JavaScript code.


var functionOne = function() {
        // Some code


function functionTwo() {
        // Some code

Are both of these methods correct? If so in which occasions are these used?



  • DavidMDavidM USAMember Posts: 342
    edited February 2014

    There is a difference. functionOne is defined at run time. functionTwo is defined at parse-time for a script block. functionOne will give an error.

Sign In or Register to comment.