Understanding JavaScript Truthy and Falsy

后端 未结 7 1885
深忆病人
深忆病人 2020-11-22 08:20

Can someone please explain JavaScript Truthy and Falsy, using the below sample data. I have read other threads but still confused.

var a = 0;

var a = 10 ==          


        
相关标签:
7条回答
  • 2020-11-22 09:00

    In JavaScript, && and || don't always produce a boolean value. Both operators always return the value of one of their operand expressions. Using the double negation !! or the Boolean function, "truthy" and "falsy" values can be converted to proper booleans.

    true && true =>
    true
    
    true && false =>
    false
    
    true && 'rahul626'=>
    "rahul626"
    
    true && 'i am testing Truthy' && ' upvote it'=>
    " upvote it"
    

    Try, tried on console

    Well described here

    0 讨论(0)
提交回复
热议问题