Which example is a valid variable name in JavaScript?

Prepare for the uCertify CIW Advanced HTML5 and CSS3 Specialist Exam. Dive into essential topics with flashcards and multiple-choice questions. Enhance your understanding with hints and explanations for each question. Pass your exam confidently!

Multiple Choice

Which example is a valid variable name in JavaScript?

JavaScript identifiers must start with a letter, a dollar sign, or an underscore, and may continue with letters, digits, dollar signs, or underscores. They cannot start with a digit and they cannot contain hyphens or other punctuation. The underscore-leading example is valid because it begins with an allowed character and uses only permitted characters afterward. The option that starts with a digit breaks the rule and isn’t valid. The one with a hyphen isn’t valid because the hyphen isn’t allowed in identifiers. Digits can appear after the first character, so something like name1 is also valid, but the key point shown here is that starting with an underscore is a perfectly acceptable and common way to name a variable.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy