美文网首页
undefined和null在cookie中的妙用

undefined和null在cookie中的妙用

作者: jasonhsu9 | 来源:发表于2018-12-03 17:16 被阅读0次

JS中:undefined == null会返回什么?
直接测试:

undefined == null //true
undefined === null // false

同理可得

//不等于
undefined != null  //false

//不完全等于
undefined !== null // true

一个函数的参数para,只要传递了数据,则para != null 为true
此特性的用途?

function foo(para) {
    if (para != null) {
        console.log(para);
    } else {
        return "请您传递一个参数给我"
    }
}

因为一个函数foo(para)调用时,参数para未传递,则其值是undefined,所以这个特性可用于:当函数调用时,是否传递参数的判断
此文:cookie是什么?cookie的设置/修改/获取/删除 的setCookie方法,就用到了这个逻辑。

相关文章

网友评论

      本文标题:undefined和null在cookie中的妙用

      本文链接:https://www.haomeiwen.com/subject/osnycqtx.html