javascript技术栈 - Day01 : 只有不猝死 , 就往死里卷 ~~~
一、javascript的根本数据类型有哪些
null undefinedbooleanstringnumberbigintsymbol
二、null根本类型的具体应用
1.null的作用个别是申明一个变量行将绑定一个对象,然而未绑定对象前的一个申明
let hd; hd = null; // hd变量行将绑定一个援用类型hd = { name : "范冰冰" }
- 2.a变量是一个援用类型,咱们将a变量赋值给b变量,此时咱们再将a赋值为null,那么b是null还是援用a的内存地址???
let a = {name : "王百强"}let b = a;a = null; // a ---> null console.log(b); // b ---> {name : "王百强"}
- 3.null的隐式类型转换
1. 转换为string类型null + 'hello' // 'nullhello' 字符串与任何类型相加都是拼接String(null)// null (切记 : null没有办法)2. 转换为number类型123 * null // 0 (null被转换为number类型的时候就是数值0)123 + null // 123Number(null) // 0parseInt(null) // NaN (无奈计算转换)3. 转换为boolean类型Boolean(null) // falsenull + true // 1 (null会转换为0,true会转换为1)4. typeof null // object
三、undefined根本类型的详情应用
1. 变量申明未赋值let hd // undefinedvar hd // undefined2. 函数中的形参未赋值function show(a,b){}show(1) // b = undefined3. 函数没有return 返回值function show(){}show() // undefined4. typeof undefined // undefined5. 转换为string类型let hdhd + 'hello' // 'undefinedhello' (任何值和字符串相加都是相拼接操作)6. 转换为number类型let hdNumber(hd) // NaN (无奈转为Number类型)1 + undefind // NaN1 - undefined // NaN7. 转换为Boolean类型Boolean(undefined) // false1 + true // NaN1 - false // NaN
四、string根本类型的应用
1、string字面量的创立办法let str = 'hello world; console.log(typeof str) // string2、通过构造函数创立字符串类型let str = new String(); console.log(typeof str) // objectstr = 'hello' // string3、字符串拼接'hello' + 123/true/null/undefined // 'hello123' (都是拼接)4、转number数据类型'123' - 1 // 122123 - '2' // 121parseInt('123hello') // 123 parseInt('hello123') // NaNparseFloat('123.45hello') // 123.45parseFloat('hello123.45') // NaNNumber('123') // 123Number('hello') // NaN5. 转boolean数据类型'1' - true // 0 (都转换为number类型进行计算)Boolean('') // 0Boolean('1') // trueBoolean('hello') // true6. string数据类型的本身属性let str= 'hello world'str.length; // 字符串的长度 (本身属性)7. string数据类型的原型对象中的属性和办法let str = 'hello'new str.constructor(); // 创立新的String对象8. String.prototype.anchor()- 创立a链接标签 let str = 'hello'str.anchor('text'); // <a name="text">str字符串的内容(hello)</a>9.charAt()- 通过索引返回字符let hd = "hello"hd.charAt(2) // lhd.charAt(4) // o10.charCodeAt()- 通过索引返回字符的unicode编码var str = "HELLO WORLD";var n = str.charCodeAt(0); // 7211.concat()- 连贯多个字符串,返回一个新的字符串,不扭转原变量值let hd = 'hello'let cms = 'world'let n = hd + cms; // 'helloworld'12.endsWith()- 以后字符串是否以该字符为结尾let hd = "hello world"hd.endWith('world') // 是的返回true ,否则返回false13.includes()- 判断以后字符串中是否蕴含该字符,返回true/falselet hd = 'houdunren cms .com'hd.includes('com') // true14.indexOf()- 通过字符返回字符串中第一个匹配到字符的索引地位- 找到返回字符的索引地位,找不到返回-1let hd = 'hello';hd.indexOf('i') // 0hd.indexOf('s') // -115.lastIndexOf()- 同indexOf,只不过从后往前检索16.match()- 次要用来匹配正则表达式的17.padStart()- 后面开始填充let full = 340102199609111678;let fullStart = full.slice(-6); // 截取后6位let newPad = fullStart.padStart(full.length,'*'); // '*'全副填充到fullStart字符串后面,总共的字符长度为full.length的长度18.padEnd()- 向前面进行填充,原理同padStart()19.repeat()- 字符串反复的次数'hello'.repeat(0) // 0'abc'.repeat(1) // abc'abc'.repeat(2) // abcabc20.replace()- 将字符串中的某些字符全副进行替换,只替换第一次匹配到的字符let hd = "www.baidu.com"hd.replace('w',"哈") // "哈ww.baidu.com" (不扭转原字符串,返回新字符串)21.replaceAll() -匹配字符串替换所有的字符串中的字符let hd = "www.baidu.com"hd.replaceAll('w','1') // '111.baidu.com'22.slice()-截取字符串,不扭转原字符串let hd = "houdunren";hd.slice(4) // 从索引4开始截止到尾hd.slice(1,3) // 从索引1截取到索引3不包含3hd.slice(-2) // 截取最初2个字符slice(-9,-5) // 从-9开始截取到-5不包含-523.split()-将字符串依照规定宰割成数组,不影响原变量let hd = "www.baidu.com"hd.split('.') // ["www","baidu","com"]24.startsWith()- 是否以某个字符串为结尾let hd = "baddu.com"hd.startsWith('bad') // 是的返回true,否则返回false25.toLowerCase()- 字符串字母小写let hd = "HOUDUNREN"hd.toLowerCase() // houdunren26.toUpperCase()- 字符串字母大写let hd = 'houdunren'hd.toUpperCase() // HOUDUNREN27.toString()- 将其余数据类型转换为字符串类型let hd = true;hd.toString() // 'true'28.trim()- 去除字符串的前后空白字符let hd = " cms ";hd.trim() // 'cms'29.valueOf()- 返回以后对象的原始值let hd = new String('foo')hd.valueOf() // 'foo'30.Symbol(Symbol.iterator)- 有该属性示意以后的变量对象能够被for...of进行遍历let cms = "houdunren"for(leyt key of cms){ key // h / o / u / d ....}