1.数据类型
1.基本数据类型
- undefined
- 没有赋值的对象
- boolean
- true和false
- string
- .length(和数组一样)
- +(字符串合并)
- string()函数
- number
- 8,10,16进制
- 科学计数法
- 值的范围:
Number.MAX_VALUE , Number.MAX_VALUE ,Infinity - NAN:是不是数值(isNAN()函数)
- parseInt(),parse(),第一个参数是要解析的数,第二个数是按多少进制转换(函数)
- number(),undefined转换为NAN
- object
- symbol
2.引用类型
1.数组
定义数组
let arr1 = new Array()
let arr2 = new Array(2)
let arr3 = new Array(10)
let arr4 = []
2.数组操作
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<script>
// 栈操作
let arr1 = new Array()
for(i=0;i<3;i++)
{
arr1.push(i);//尾插入
}
m = arr1.pop()
console.log(m);
// 队列
let arr2 = new Array(5)
arr2.fill(1);
for(i=0;i<5;i++)
{
arr2.unshift(i);//头插入
}
console.log(arr2);
console.log(arr1.reverse());//逆向
function compare(count1,count2)
{
if(count1<count2)
{
return true
}
else
{
return false
}
}
console.log(arr2.sort(compare));//排序
//1.把字符串变成数组
let str = '12345'
console.log(str.length);
let str2 = Array.from(str)
console.log(str2);
//1.1把数组变成字符串
let arrs = str2.join('')
console.log(typeof arrs,arrs);
// 2.对数组进行整体操作
console.log(Array.from(str2,function (x){return x*x;}));
// function (x){return x*x;等价于x=>x**x
// 3.把一组参数转换为数组
console.log(Array.of(1,2,3));
let strr = [1,23,4,5,6]
// 提取
console.log(strr.slice(1,3));
// splice:插入,删除等操作
</script>
</body>
</html>
2.流程控制
//分支
let count = 10;
// if语句
if(count < 10)
{
console.log(count-1);
}else if(count == 10){
console.log(count);
}else{
console.log(count+1)
}
// =>count>10?console.log(10):console.log(1);;
// while语句
let x = 1
do{
console.log(x);
x++;
}while(x<2)
// for语句
for(;x<8;x+=2)
{
console.log(x);
break;
}
// for in 语句
arr = [1,2,3]
for(i in arr)
{
print(i)
}
// break和continue
for(let i =0 ;i<5;i++)
{
if(i%3==0)
{
continue;
}
console.log(i);
}
let y = 10;
switch(y){
case 1:
console.log(1);
break;
case 2:
case 3:
// 满足2或者3输出1
console.log(1);
break;
default:
console.log(10);
}