批改状态:合格
老师批语:
变量(区分大小写)
变量初始化
var x =3;console.log(X)声明变量,变量赋值
// 声明变量var x;// 变量赋值x = 3;console.log(x)
const 建议使用
const x =3console.log(x)var初始化,可以重新赋值
var x =3;x=5;console.log(x)
变量类型
基本的数据类型
Number String Boolean undefined null
引用的数据类型
Object Array Function
1.Number (数值类型)
const a =4;const b = 1.234;const c =-1;console.log(typeof a);console.log(typeof b);console.log(typeof c);字符拼接
const a = '3';const b ='5'const c = a+bconsole.log(c);2.string,使用双引号或是单引号 (字符串)
const a ='chw';const b = "1.234";const c ='-1';console.log(typeof a);console.log(typeof b);console.log(typeof c);3.boolean 0(假 false) 和1(真 true)
var c = 3 <= 4;alert(c);alert(typeof c);4.undefined
var x;console.log(x)5.数组(支持下标索引取值)
const a = ['3',"chen",4,5];console.log(a[1])二维数组
const a = ['3',"chen",[4,5]];console.log(a)contst可以增删改
const chw = [1, 2, 3]chw[1]=5console.log(chw)
对象
let user={id:1,name:"chen",tell:"18111","printtt":function(){console.log('我的姓',this.name);}}console.log(user.id,user.name,user['printtt'])
使用contst,不存在a++等于a=a+1,c=a+5等于c+=5
const a = 3;const b = 4;const c = a + b;const d = a * b;const e = 3 - 4;const f =c+3;console.log(c);console.log(d);console.log(e+3*c);console.log(f);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号