What is the difference between these two functions/approaches?

前端 未结 4 1516
南旧
南旧 2020-12-06 07:10

I use only jQuery for writing JavaScript code. One thing that confuses me is these two approaches of writing functions,

First approach



        
4条回答
  •  再見小時候
    2020-12-06 07:46

    The first one is a function expression,

    var calculateSum = function(a, b) { return a + b; }
    
    alert(calculateSum(5, 5)); // Alerts 10
    

    The second one is a plain function declaration.

提交回复
热议问题