how to compare two string with not equal to ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2021 10:02 AM
how to compare two string with not equal to ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2021 09:31 AM
There are two approaches:
Method 1 (!==not equal) //recommend
var str_1 ="test 1";
var str_2 = "test 2";
if (str_1 != str_2 ){ //true
alert("str_1 != str_2");
}else{
alert("str_1 == str_2");
}
Method 2 (!== not equal value or not equal type)
if (str_1 !==str_2 ){ //true
//do something
}else{
//do something
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2021 10:14 AM
A nice alternative using ternary operator:
var isNotEqual = "string1" !== "string2" ? "true" : "false";
gs.log(isNotEqual);
Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2021 06:48 AM
Please let me know if this resolved your query.
Geoff