if (typeof foo !== 'undefined') { // Now we know that foo is defined, we are good to go. }
typeofevaluated as trueor falsedepending on whether the variable is defined foo.
typeof
true
false
foo
But, say, if it foo !== 'undefined'is evaluated as true, then typeofof trueshould be evaluated to 'boolean'. Why does he value trueor false?
foo !== 'undefined'
'boolean'
Because the precedence rules for operators typeofand inquality determine that this expression is parsed as
(typeof foo) !== 'undefined'
. MDN . typeof - 16; Inquality 10. typeof , " " .
Source: https://habr.com/ru/post/1666635/More articles:Search for .NET Core or Standard NuGet Packages - c #Python Pandas: discard strings of different times based on time range - pythonnew T (...) vs std :: make_unique (...). release () - c ++Spring Binding MVC in a typed field - javaHow to use local dependencies in Clojure? - mavenangular2 material design - reactive forms - md-select is not populated with default value - angularPassing id via href link in Laravel - phpСкопируйте один слайд из презентации Google в новую презентацию google, используя API - rubyInconsistent information in Git (log vs. diff) about one file - gitCopy one slide from a Google presentation to a new google presentation using the API - ruby | fooobar.comAll Articles