编辑代码

// Boolean
let bo = new Boolean(true)

console.log(typeof bo) // object
console.log(typeof bo.valueOf(), typeof bo.toString())

let bo1 = true

console.log(typeof bo1) // boolean

// Number
let num = new Number(10)

console.log(typeof num) // object
console.log(typeof num.valueOf(), typeof num.toString())

let num1 = 10

console.log(typeof num1) // number

// String
let str = new String('helloworld')

console.log(typeof str) // object
console.log(typeof str.valueOf(), typeof str.toString())

let str1 = 'helloworld'

console.log(typeof str1) // string

console.log(str1.slice(1, 4)) // 负值会和 长度相加得到一个值
console.log(str1.substring(1, 4)) // 负值将会被转换为 0
console.log(str1.substr(1, 4)) // 负值会和 长度相加得到一个值

var text = "cat, bat, sat, fat";
text.replace('at', 'end') // 只替换第一个字符串
console.log(text)

text.replace(/at/g, 'end') // 会替换所有的
console.log(text)

// fromCharCode 字符编码转换为字符
alert(String.fromCharCode(104, 101, 108, 108, 111)); //"hello"