I know that Javascript’s eval can evaluate expressions like
(true) && (false)
(true) || (false)
etc.
However, does the specification of eval include evaluating statements involving unknowns like
(true) && (null)
(true) || (null)
(null) && (null)
(null) || (null)
etc.
I have tried this in code and seen that it does it, but is this expected behavior? Do the Javascript eval specifications say this?
Define “correct”. Javascript defines the behavior.
Evalin Javascript evaluates the string as a javascript code. SQL defines the behavior as well. The behavior is different in both.In javascript,
nullacts likefalsein boolean expressions (is falsy).0,NaN,"",null,undefined(and of coursefalse) are all falsy. Objects, non-empty strings and non-zero numbers (and of coursetrue) are all truthy.&&returns the first falsy argument (if any) or the last argument (lazy AND) and does not evaluate the rest.null && "anything"isnull. This can be used in statements likeconsole && console.log && console.log().||returns the first truthy argument (if any) or the last argument (lazy OR) and does not evaluate the rest.null || "something"is"something". This can be used in statements likevar xhr = XmlHttpRequest || ItsReplacementInOlderBrowsers!nullevaluates totrue.if(null) ...evaluates theelsebranch. The same applies to anything falsy.Technically, undefined variables are
undefined, notnull. Both are falsy, though.