&& operator in Javascript

后端 未结 4 767
清歌不尽
清歌不尽 2020-11-29 06:27

While looking through some code (javascript), I found this piece of code:



        
4条回答
  •  心在旅途
    2020-11-29 06:37

    && is an AND operator, just like most everywhere else. There is really nothing fancy about it.

    Most languages, JavaScript included, will stop evaluating an AND operator if the first operand is false.

    In this case, if window.Bootloader does not exist, it will be undef, which evaluates to false, so JavaScript will skip the second part.

    If it is true, it continues and calls Bootloader.done(...).

    Think of it as a shortcut for if(window.Bootloader) { Bootloader.done(...) }

提交回复
热议问题