[removed] querySelector Null vs querySelector

后端 未结 4 1652
既然无缘
既然无缘 2020-12-18 21:41

What is the main difference between these two methods of referencing?

What are the benefits of using one or the other? Also what kind of usage-case would they each

4条回答
  •  庸人自扰
    2020-12-18 22:33

    The first statement contains a bool value depends on document.querySelector('.selector') is null or not

    var selection = document.querySelector('.selector') !== null;
    

    the second statement contains the actual value of document.querySelector('.selector');

    var selection = document.querySelector('.selector');
    

提交回复
热议问题