Exclamation Mark Behind Assigned Value: A = B ! C
Solution 1:
Looks like FreeMarker template language, and yes, the !
operator, when appears on the right side of an operand gives a default value if the left side expression is null
or a reference to a missing variable.
Solution 2:
well, your code is wrong and cannot be parsed. You might even get a weird not understandable error.
Does it mean that if first value is
NULL
the second on should be placed inseriesCode
?
no, it's just wrong and cannot be understood by javascript. !
is a unary operator, so it's likely to fail in weird ways if you try to use it as a binary operator (in between two values).
What you're asking is done using the ||
operator:
seriesCode = pageRecord.getProperty('seriesCode')||'XXX';
you might see a trick with the !
unary operator, though being the double exclamation mark:
existsSeriesCode = !!pageRecord.getProperty('seriesCode');
the idea here is that with the first exclamation mark, you're converting your object into a boolean, where false
means this variable is a reference to an instance, and true
means the variable contains either null
or undefined
. Then the second exclamation mark is there to negate it again, meaning that true
contains an instance, false
contains either undefined
or null
.
Post a Comment for "Exclamation Mark Behind Assigned Value: A = B ! C"