When checking for a null or empty variable, do you...
# suitescript
n
When checking for a null or empty variable, do you guys use xyz == "" && xyz == null OR xyz == "" || xyz == null OR something else ?
b
if (!xyz) {}
thumbs up 1
1
n
does that work in all cases?
d
if you're checking strings, yes. but don't forget that zero is falsey. If I know the variable's datatype (like, if I'm calling
record.getValue()
) then I'll explicitly check
if (xyz === '') {}
or
if (xyz !== '') {}
1
c
You can cast a truthy or falsey variable to a boolean using the double !!
message has been deleted
👍 1