Question
Download Solution PDFWhat will be the output of the follwing Javascript code snippet?
console.log(25= "25");
console.log(92 "92");
This question was previously asked in
Beltron Programmer 1 Oct 2023 Official Paper
Answer (Detailed Solution Below)
Option 4 : true
true
true
Free Tests
View all Free tests >
Beltron Programmer Mock Test
0.8 K Users
20 Questions
20 Marks
24 Mins
Detailed Solution
Download Solution PDFThe correct answer is Option 4) true true.
Key Points
==
is a loose equality operator in JavaScript.- It compares two values for equality after converting both values to a common type (type coercion).
- In the expression
25 == "25"
:- JavaScript converts the string
"25"
to number25
- Hence,
25 == 25
results intrue
- JavaScript converts the string
- Similarly,
92 == "92"
also returnstrue
due to type coercion.
Additional Information
- If we used
===
(strict equality), then:25 === "25"
would returnfalse
since number and string types don’t match.
- For type-safe comparison, use
===
instead of==
to avoid unexpected results due to type coercion.
Conclusion: Both statements return true because of JavaScript's type coercion using the ==
operator.
Last updated on Nov 25, 2024
-> BELTRON Programmer 2024 Notification has been released on the official website.
-> The Bihar State Electronics Development Corporation Limited (BELTRON) has announced a recruitment drive for Programmer positions on a contractual basis.
-> Specific vacancy details will be shared separately.
-> Interested candidates can apply online from November 11, 2024, to December 10, 2024.
-> The Minimum age of the candidates should be 21 years and maximum age should be 59 year of age.