四十分钟JavaScript快速入门 | 无废话且清晰流畅 | 手敲键盘 ...

// The test is note.
// Date 2023.09.05
// Night
// 你好,世界!
console.log("hello world!");
// var 全局变量
// let 局部变量
let age=30;
console.log(age);
//const aae;XXXXXXXd
// const 定义的变量此后不能修改
const media = 40;
//media = 50;
console.log(media);
// 数据的基本类型
let ade;
ade = 'a';
console.log(ade);
const me = "wdasdw";
console.log(me);
const name1 = "woder";
console.log(name1);
const raer = undefined;
console.log(raer);
const iscook = false;
console.log(iscook);
const isfile = true;
console.log(isfile);
const num1 = 1;
console.log(num1);
const num2 = 2.2;
console.log(num2);
console.log(typeof isfile);
console.log(typeof num1);
const unnum=null;
console.log(unnum);
console.log(typeof unnum);
console.log(typeof raer);
// confirm(typeof num1);
// confirm 弹出
// 控制台“+”输出
console.log("hello"+' '+"world");
const usname ="Make";
const age1 = 30;
// 控制台输出模块化
console.log(`My name is ${usname} and I am ${age1}`);
// 定义字符串
const s1 = "Hello world";
// 长度
console.log(s1.length);
// 大写
console.log(s1.toUpperCase());
// 小写
console.log(s1.toLowerCase());
console.log(s1.substring(0,5));
console.log(s1.split(""));
console.log(s1.split(", "));
// 数组
const num123=new Array(1,2,3,4,5,6,7,8,9);
console.log(num123);
// 数组的简单定义
const number = ["asd0",'dwad','dwadasufg',true,null,10];
console.log(number);
console.log(number[0]);
// 在末尾加上
number.push("NewAdd");
console.log(number);
// 在头部加上
number.unshift("Fornt");
console.log(number);
// 删除末尾的
// number.pop();
console.log(number);
// 判断数据是否为数组
console.log(Array.isArray('hello'));
console.log(Array.isArray(number));
// 得到索引
console.log(number.indexOf("asd0"));
// 数组的更多操作可看js文档
// 对象
const person ={
firstName:"Make",
lastName:"Dan",
age:30,
hobbies:["Music","Movies","Sports"],
address:{
street:"50 main St",
city:"WuHan",
state:"MA",
},
};
console.log(person);
console.log(person.firstName);
console.log(person.address.street);
// 抽象剥离
const {firstName, lastName ,address:{city},} = person;
console.log(firstName);
console.log(city);
// 添加属性
person.email = "Make@mail.com";
console.log(person);
// 对象数组
let result = [
{
id:1,
subject: 'math',
score: 10,
isGood:false,
},
{
id:2,
subject: 'chinese',
score: 20,
isGood:false,
},
{
id:3,
subject: 'english',
score: 30,
isGood:true,
}
];
// 下标
console.log(result[1].subject);
// 对象数组转化为JSON
const resultJSON = JSON.stringify(result);
console.log(resultJSON);
// if
const xx=4;
// === 考虑数据类型 == 不考虑
if (xx === 10){
console.log("xx is 10");
} else{
console.log("xx is not 10")
}
if (xx == 10){
console.log("xx is 10");
}
if (xx > 10){
console.log("xx > 10");
}
const yy =11;
if (yy > 5 || yy > 10){
console.log("xx > 5 or yy > 10");
}
if (yy > 100 && yy > 10){
console.log("xx > 100 and yy > 10");
}
// 三目运算符
const xxx=10;
const color = xxx > 10 ? 'red' : 'blue';
console.log(color);
// switch
switch(color){
case 'red':
console.log("color is red");
break;
case 'blue':
console.log("color is blue");
break;
default:
console.log("color is Not red or blue");
}
// for and while
for (let i =0;i<10;i++){
console.log(i);
}
console.log("-----");
let i = 0;
while (i < 10) {
console.log(i);
i+=2;
}
let result1s = [
{
id:1,
subject: 'math',
score: 10,
isGood:false,
},
{
id:2,
subject: 'chinese',
score: 20,
isGood:false,
},
{
id:3,
subject: 'english',
score: 30,
isGood:true,
}
];
// 循环打印result1s中的每一项 类似于python的for x in xs():
for (let result1 of result1s){
console.log(result1);
}