javascript技术栈-Day01:只要不猝死,滚死就行~~~1、javascript的基本数据类型有哪些?nullundefinedbooleanstringnumberbigintsymbol二、null基本类型使用详解1、null的作用一般是声明一个即将被绑定的变量一个对象,但是在未绑定对象之前声明lethd;高清=空;//hd变量即将绑定一个引用类型hd={name:"FanBingbing"}2.a变量是一个引用类型,我们将a变量赋值给b变量。这时候我们把a的值赋给null,那么b是null还是引用a的内存地址???leta={name:"王百强"}letb=a;a=null;//a--->nullconsole.log(b);//b--->{name:"WangBaiqiang"}3.null的隐式类型转换1.转换为字符串类型null+'hello'//'nullhello'字符串对任意类型的加法是一个串接String(null)//null(记住:null没有方法)2.转为number类型123*null//0(null为0时转为number类型)123+null//123Number(null)//0parseInt(null)//NaN(无法计算转换)3.转换为boolean类型Boolean(null)//falsenull+true//1(null会转换为0,true会转换为1)4.typeofnull//object3.undefined基本类型使用细节1.变量声明unassignedlethd//undefinedvarhd//undefined2.函数中的形参unassignedfunctionshow(a,b){}show(1)//b=未定义3。函数没有返回值functionshow(){}show()//undefined4.typeof未定义//未定义5。转成字符串类型lethdhd+'hello'//'undefinedhello'(任意值和字符串相加是拼接操作)6.转成数字类型lethdNumber(hd)//NaN(不能转成数字类型)1+undefind//NaN1-undefined//NaN7。转换为布尔类型Boolean(undefined)//false1+true//NaN1-false//NaN4.字符串基本类型的使用1.字符串字面量创建方法letstr='helloworld;console.log(typeofstr)//string2,通过构造函数创建字符串类型letstr=newString();console.log(typeofstr)//objectstr='hello'//string3,stringconcatenation'hello'+123/true/null/undefined//'hello123'(bothconcatenation)4,转换为数字数据类型'123'-1//122123-'2'//121parseInt('123hello')//123parseInt('hello123')//NaNparseFloat('123.45hello')//123.45parseFloat('hello123.45')//NaNNumber('123')//123Number('你好')//NaN5.转换为布尔数据类型'1'-true//0(转换为数字类型进行计算)Boolean('')//0Boolean('1')//trueBoolean('hello')//true6.string数据类型的自身属性letstr='helloworld'str.length;//字符串的长度(自身属性)7.字符串数据类型的原型对象中的属性和方法letstr='你好'newstr.constructor();//创建一个新的String对象8.String.prototype.anchor()-创建一个链接标签letstr='hello'str.anchor('text');//contentofstrstring(hello)9.charAt()-按索引返回字符lethd="hello"hd.charAt(2)//lhd.charAt(4)//o10.charCodeAt()-通过索引返回字符的unicode代码varstr="HELLOWORLD";varn=str.charCodeAt(0);//7211.concat()-连接多个字符串并返回一个新字符串,不改变原来的变量值lethd='hello'letcms='world'letn=hd+cms;//'helloworld'12.endsWith()-当前字符串是否以该字符结尾lethd="helloworld"hd.endWith('world')//是则返回true,否则返回false13.includes()-判断该字符是否包含在当前字符串中,返回true/falselethd='houdunrencms.com'hd.includes('com')//true14.indexOf()-返回第一个匹配字符在字符串中的索引位置通过字符-找到返回字符的索引位置,返回-1lethd='hello';hd.indexOf('i')//0hd.indexOf('s')//-115.lastIndexOf()-同asindexOf,但从后往前查找16.match()-主要用于匹配正则表达式公式17.padStart()-填写前面letfull=340102199609111678;letfullStart=full.slice(-6);//截取l的后6位etnewPad=fullStart.padStart(full.length,'*');//'*'全部填充在fullStart字符串前面,总字符长度为full.length的长度18.padEnd()-padding到后面,原理同padStart()19.repeat()-字符串重复的次数'hello'.repeat(0)//0'abc'.repeat(1)//abc'abc'.repeat(2)//abcabc20。replace()-替换字符串中的所有字符,只替换第一次匹配到的字符lethd="www.baidu.com"hd.replace('w',"ha")//"Hawww.baidu.com"(不改变原字符串,返回新字符串)21.replaceAll()-匹配字符串替换字符串中的所有字符lethd="www.baidu.com"hd.replaceAll('w','1')//'111.baidu.com'22.slice()-截取字符串,不改变原字符串lethd="houdunren";hd.slice(4)//从索引4开始到结束hd.slice(1,3)//从索引1截取到索引3不包括3hd.slice(-2)//截取最后2个字符slice(-9,-5)//从-9开始截取到-5不包括-523.split()-将字符串按规则拆分成数组,不影响原变量lethd="www.baidu.com"hd.split('.')//["www","baidu","com"]24.startsWith()-是否以某个字符串开头lethd="baddu.com"hd.startsWith('bad')//是返回true,否则返回false25.toLowerCase()-字符串字母小写lethd="HOUDUNREN"hd.toLowerCase()//houdunren26.toUpperCase()-大写字符串字母lethd='houdunren'hd.toUpperCase()//HOUDUNREN27.toString()-将其他数据类型转换为字符串类型lethd=true;hd.toString()//'true'28.trim()-去除字符串的前导和尾随空白字符lethd="cms";hd.trim()//'cms'29.valueOf()-返回原来的当前对象的值lethd=newString('foo')hd.valueOf()//'foo'30.Symbol(Symbol.iterator)-这个属性表示可以通过for...遍历当前变量对象ofletcms="houdunren"for(leytkeyofcms){key//h/o/u/d....}