1D0-735 practice question 12 of 15
Which of the following will correctly declare the courseNumber variable as a siring data type?
Full set: 55 questionsIn JavaScript, variables are declared using keywords like var. A string data type, or string literal, must be enclosed in a matching pair of single (') or double (") quotation marks. The question asks to declare the variable courseNumber as a string. Options A and B are identical and contain the correct keyword (var) and variable name (courseNumber). The value ''JS101'' is syntactically incorrect. Assuming '' is a typographical error for " (double quotes), the statement would become var courseNumber = "JS101";, which is the correct way to declare a variable and assign it a string value.
C. This option is incorrect for two reasons: it uses the wrong variable name (varcourseNumber instead of courseNumber) and the value JS101'' is a malformed string literal, causing a syntax error.
D. This option assigns the value JS101 without quotes. JavaScript interprets this as an identifier (e.g., another variable), not a string literal. This does not satisfy the requirement to assign a string data type.
1. Mozilla Developer Network (MDN) Web Docs: "String literals are enclosed by single (') or double (") quotes... The var statement declares a function-scoped or globally-scoped variable, optionally initializing it to a value."
Source: MDN Web Docs, JavaScript Guide > Grammar and types. (Specifically sections on Literals and Declarations).
2. Eloquent JavaScript, 3rd Edition by Marijn Haverbeke: "To create a string value, you write its content between quotes... Both single and double quotes can be used to mark strings... Keywords and variable names are identifiers."
Source: Haverbeke, M. (2018). Eloquent JavaScript (3rd ed.). No Starch Press. Chapter 1, "Values, Types, and Operators," and Chapter 2, "Program Structure."
3. MIT OpenCourseWare: Course materials for 6.001 Structure and Interpretation of Computer Programs emphasize that string literals are sequences of characters delimited by quotation marks, while identifiers (variable names) are not quoted.
Source: MIT OCW, 6.001 Structure and Interpretation of Computer Programs, Fall 2007. Lecture notes on JavaScript syntax.
Keep practicing
Take the free 1D0-735 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1D0-735 practice questions
- Question 3Which of the following is an advantage of using the Virtual DOM?
- Question 4Which of the following comparison statement will return true? A) X=10; Y=11; y--; x==y B)…
- Question 6Marshall's computer previously contracted malware because he unknowingly clicked on an in…
- Question 7Which of the following is not a best practice when using JavaScript libraries?
- Question 10Scarlet has the following code in her script: Var namesArr =[‘’Joseph’,’ Charlotte’’, ‘’N…
- Question 11Which of the following comparison statements will return true?
