exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 2 question 8 discussion

Actual exam question from Microsoft's 70-480
Question #: 8
Topic #: 2
[All 70-480 Questions]

You are testing the value of the following variable in JavaScript. var height = "300";
A block of code must execute if the following conditions are true:
✑ The height variable is set to 300
✑ The height variable is of type string
You need to implement the code to run the test.
Which line of code should you use?

  • A. if (height = = 300)
  • B. if (height = = "300")
  • C. if (height ! "300")
  • D. if (height ! = 300)
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
Use = = to test for equality.
Use "300" to test for the string.

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Piggas
Highly Voted 5 years, 9 months ago
Answer A and B is the same. If B is correct answer, then B should be written as "if (height === "300") with the 3 equal sign operators to test for type and value
upvoted 15 times
...
JMz123
Highly Voted 5 years, 6 months ago
Since A and B do not do type checking, or rather coerce types, they are the same answer, as Piggas pointed out. And yest to get both conditions it needs to be if (height === "300")
upvoted 5 times
...
alezvic2
Most Recent 4 years, 4 months ago
As other pointed out, it'd be correct to use height === "300" to check for type. Both height == 300 and == "300" return true but in neither case we can confirm the type of height.
upvoted 2 times
...
NellyM
4 years, 6 months ago
A is not of string type.B is correct
upvoted 1 times
...
JMz123
5 years, 6 months ago
spaces in the middle of an operator FAIL
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago