How do you write a function expression in JavaScript?

How do you write a function expression in JavaScript?

a) let myFunction = function() { … }
b) function = myFunction() { … }
c) def myFunction() { … }
d) fn myFunction() { … }

Answer:

a) let myFunction = function() { … }

Explanation:

In JavaScript, a function expression is a function assigned to a variable. The function can be called using the variable name.

Example:


let greet = function() {
    console.log("Hello, World!");
};
greet(); // Output: "Hello, World!"
    

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top