0 votes
in JavaScript by
What's the output?
const name = 'Lydia';

console.log(name());
  • A: SyntaxError
  • B: ReferenceError
  • C: TypeError
  • D: undefined

1 Answer

0 votes
by
Answer: C

The variable name holds the value of a string, which is not a function, thus cannot invoke.

TypeErrors get thrown when a value is not of the expected type. JavaScript expected name to be a function since we're trying to invoke it. It was a string however, so a TypeError gets thrown: name is not a function!

SyntaxErrors get thrown when you've written something that isn't valid JavaScript, for example when you've written the word return as retrun. ReferenceErrors get thrown when JavaScript isn't able to find a reference to a value that you're trying to access.

Related questions

0 votes
asked Mar 7 in JavaScript by DavidAnderson
0 votes
asked Feb 27 in JavaScript by DavidAnderson
...