PdfPrep.com

Which lines of code should you use?

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.)
A . if (length = = = 75)
B . if (length = = 75)
C . if (length! = 75)
D . if (length = = "75")

Answer: B, D

Explanation:

When comparison is made using double-equals operator (==), it will check the values of variable and convert them to a common type and returns true if both are equals. So comparing number with string having the same value will return true.

Examples:

examples:

1

console.log(23 == "23"); // true

2

console.log(1 == true); // true

Incorrect:

not ===: This is “strict” or “identical” equality.

Reference: JavaScript Triple Equals Operator vs Double Equals Operator ( === vs == )

Exit mobile version