Programming in HTML5 with JavaScript and CSS3 — Question 71
You need to test the value of the following variable in JavaScript. var length = "75";
A block of code must execute if the length equals 75 regardless of the data type.
You need to use the statement that meets this requirement.
Which lines of code should you use? (Each correct answer presents a complete solution. Choose two.)
Answer options
- A. if (length = = = 75)
- B. if (length = = 75)
- C. if (length! = 75)
- D. if (length = = "75")
Correct answer: B, D
Explanation
Option B is correct because it uses loose equality (==) which allows comparison between different data types. Option D is also correct as it checks for equality with the string '75', which matches the variable's value. Options A and C are incorrect since A uses strict equality (===), which would not match due to type difference, and C checks for inequality, which does not meet the requirement.