70-480 Exam QuestionsBrowse all questions from this exam

70-480 Exam - Question 16


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.)

Show Answer
Correct Answer: BD

In JavaScript, the double-equals operator (==) performs type coercion, meaning it compares the values after converting them to a common type. This allows for comparison of variables with different data types but the same value. Therefore, both 'if (length == 75)' and 'if (length == "75")' will return true because the string '75' will be coerced to the number 75 for comparison. The other options are incorrect because the triple-equals operator (===) does not perform type coercion and requires both the type and value to be the same, and the inequality operator (!=) would not satisfy the requirement of the code block executing if the length equals 75.

Discussion

2 comments
Sign in to comment
JMz123
Oct 22, 2019

Wow. Most (all?) programming languages do not allow spaces in '==' or '===' or '!='. In addition, best practice is to leave a space around the operators. To wit, if ( 77 == value )

superhands
Apr 16, 2020

technically none of the options are correct due to the fact that spaces in-between the equal signs will not work in the browser. i guess the intention is to just pretend the spaces are not there