nerdexam
CIW

1D0-720 · Question #59

Which syntax correctly defines a function in JavaScript?

The correct answer is A. function myFunction() { ... }. Option A uses the function keyword followed by a name and parentheses - this is the standard function declaration syntax in JavaScript and has been valid since the language's inception. Option B is wrong because var declares a variable, not a function, and attaching parentheses…

Client-Side Scripting and Media Queries

Question

Which syntax correctly defines a function in JavaScript?

Options

  • Afunction myFunction() { ... }
  • Bvar myFunction() { ... }
  • CmyFunction[] = { ... }
  • Dfunction:myFunction() { ... }

How the community answered

(43 responses)
  • A
    93% (40)
  • C
    2% (1)
  • D
    5% (2)

Explanation

Option A uses the function keyword followed by a name and parentheses - this is the standard function declaration syntax in JavaScript and has been valid since the language's inception. Option B is wrong because var declares a variable, not a function, and attaching parentheses to it is a syntax error. Option C uses square brackets, which are for array indexing or destructuring, not function definitions. Option D inverts the colon syntax from object/label notation and is simply not recognized by the JavaScript parser.

Memory tip: Think of it as an English sentence - "function myFunction does something" - the keyword function always leads, the name follows, then () for parameters and {} for the body.

Topics

#function declarations#JavaScript syntax#basic syntax#function definition

Community Discussion

No community discussion yet for this question.

Full 1D0-720 Practice