last day (14 days later) » 

11:24 AM
2
A: Comparison of two String is not working in script

Tirthraj BarotAs mentioned in your question, if one string i fetched by you and the other string is "null", It is a clear question of string comparison and not checking null... Javascript has localeCompare() method to compare strings.. You should use entry.personalization.localeCompare("null"); or its i...

 
m already try localeCompare() but result is same.....
 
what does it return console.log(entry.personalization)
 
actually i dont know how to use console.log() so i will update the result soon
 
no problem... let me tell you.... console.log() is a function which will log the values inside the console... If you want to see it, press F-12 on your keyboard with a browser open and go to its console tab... you will see the value of console.log() in it...
 
yaa it's show null in the result
 
11:24 AM
that means your entry.personalization holds null.. and not "null"
try console.log(entry)
 
oky
the Result is
Object {title: "Thar Ke Papad", quantity: "1", personalization: null}
 
see... so here the null is not a string...
and you cannot compare a null to a string..
 
ohh so i have to typecast into the string
and after that compare with the null
casting
*
 
Exactly! Brilliant !
 
Actually i m new
in coding
 
11:29 AM
if you find it useful, please mark me as correct and vote me up...!
 
absolutely
 
Waiting..!
 
hehe
 
:D and a vote up too.. :D :D :D
 
already upvote
can u tell e how can i cast
it's easy for me
 
 
3 hours later…
2:07 PM
The ToString function (that exists internally, not in userland) is defined as follows (9.8):

"The abstract operation ToString converts its argument to a value of type String according to Table 13"

Argument Type | Result
Null | "null"
Undefined | "undefined"
This means that String(null) and String(undefined) go into this special table of types and just return the string values valued "null" and "undefined".

A user-land pseudo-implementation looks something like this:

function MyString(val) {
so you need to make one such function.. that will make the casting easy for null because it cannot be casted into a string by toString function..
Here is a question which correlates to it..
13
Q: Why does String(null) work?

KooiIncnull and undefined don't have a toString or valueOf method. Afaik using String calls the toString method of its parameter (e.g. String({}) => [object Object]). Why do String(null) or String(undefined work then? It doesn't implicitly do Object.prototype.toString.call(null). because that evaluate...

 

last day (14 days later) »