What is is a javascript function expression?



  • Function Expression

    The function expression is storing the function in a variable.

    Below is a syntax for a function expression.

    variable = function(a, b ) { code to execute }

    Example of a function expression.

    let x = function (a, b) { return a + b }
    

    Using the function expression.

    let x = function (a, b) { return a + b }
    
    let sum = x(5, 5)
    console.log(sum)
    

    Result.

    10
    


© Lightnetics 2024