How to check undefined variable in a ternary operator?

后端 未结 3 1363
别那么骄傲
别那么骄傲 2021-02-14 17:02

I have an issue with ternary operation:

let a = undefined ? \"Defined!\" : \"Definitely Undefined\",
    b = abc ? \"Defined!\" : \"Definitely Undefined\", // Re         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 17:18

       state = (typeof state !== "undefined") ? state : '';
    

    This way you can check undefined variable in a ternary operator.

提交回复
热议问题