What is the purpose of a plus symbol before a variable?

后端 未结 4 1746
死守一世寂寞
死守一世寂寞 2020-11-22 09:39

this really sounds like a simple question but I had no luck searching. what does the +d in

function addMonths(d, n, keepTime) { 
    if (+d) {
         


        
4条回答
  •  盖世英雄少女心
    2020-11-22 10:36

    The + operator returns the numeric representation of the object. So in your particular case, it would appear to be predicating the if on whether or not d is a non-zero number.

    Reference here. And, as pointed out in comments, here.

提交回复
热议问题