Regarding Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:28 AM - edited 11-30-2023 08:29 AM
Hi Community ,
var a = true;
if (a == "true") {
gs.info("inside if");
} else {
gs.info("inside else");
}
Need to know why its output is coming as - inside else
Can someone explain it to me in simple words ?
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:45 AM
You are declaring 'a' with a boolean value and testing with a string value. Boolean != string.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:47 AM
@Astik Thombare You are comparing a boolean value true with a string value "true" this check is bound to fail hence the else part is executing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:08 AM
Hi @Astik Thombare ,
I trust you are doing great.
To fix this and make the if
block execute, you could either:
- Change the condition to compare with the Boolean
true
:if (a === true)
- Or, use the strict equality operator
===
which does not perform type coercion:if (a === "true")
(but in this case, you would also need to change the value ofa
to a string:var a = "true";
)
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi