自学内容网 自学内容网

、js 相关

隐式类型转换

let num1 = '10'
let num2 = 10
console.log(num1 + num2) // 1010
console.log(num1 - num2) // 0
// 尝试类型转换
console.log('1.23' == 1.23) // true 字符串和数字可以互相转换
console.log(0 == false) // true 非零数值被视为真(true)
console.log(null == undefined) // true

判断 值和类型

对象引用比较(即比较地址)

console.log(null === null) // true
console.log(undefined === undefined) // true
console.log(NaN === NaN) // false 表示无法表示为数字的任何数值
console.log(new Object() === new Object()) // false 对象引用(即地址)并不相等
console.log({} === {}) // false 比较对象按引用而不是值

typeof

console.log(typeof NaN) // number 历史原因和设计决策
console.log(typeof 100) // number
console.log(typeof 'str') // string
console.log(typeof false) // boolean
console.log(typeof undefined) // undefined
console.log(typeof function fn() {}) // function
console.log(typeof new Object()) // object
console.log(typeof {}) // object
console.log(typeof null) // object
console.log(typeof [1, 2]) // object

instanceof

console.log([1, 2] instanceof Array === true) // true
console.log({} instanceof Array === true) // false
console.log(new Object() instanceof Object === true) // true
console.log({} instanceof Object === true) // true

复合函数 ~ 柯里化

箭头函数hello和happy

const hello = name => {
    return `hello ${name}`
}
const happy = name => {
    return `${name} :`
}

柯里化函数compose高阶函数,接受两个函数作为输入,并返回一个新的函数

const compose = (f, g) => {
    return function (x) {
        return f(g(x))
    }
}

实际上先调用happy(‘你好’)得到了"你好 :", 然后将这个字符串传递给了hello函数

const happyHello = compose(hello, happy)
console.log(happyHello('你好')) // hello 你好 :

原文地址:https://blog.csdn.net/DGogoing/article/details/142766045

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!