What is the correct way to write a function in JavaScript?

What is the correct way to write a function in JavaScript?

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

Answer:

a) function myFunction() { … }

Explanation:

In JavaScript, functions are declared using the function keyword followed by the function name and a pair of parentheses. The code to be executed is written inside the curly braces.

Example:


function greet() {
    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