Files
2024-09-27 02:06:13 +08:00

325 lines
6.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>js第一课</title>
</head>
<body>
</body>
<script>
// 变量?
// 在计算机内部用来存储东西
// 可以变的(变量内部存储的数值可以被修改)
// var 变量名称 = 变量数值
// var a = "张三"
// a = "李四"
// console.log(a);
// var a = 1,b = 1, c = 1,d = 1;
// 变量命名的规则
// 1: 变量命名首字母不能是特殊符号(_ $)
// 2: 不是纯数字
// 3: 取名字要具有含义
// 4: 变量命名首选采用驼峰命名法
// 5区分大小写
// 常量
// 在计算机内部用来存储东西
// 不可变的(变量内部存储的数值不可以被修改)
// const b = "1111"
// console.log(b);
// b = "222";
// 变量类型 (垃圾分类)
// var a = '122'; // string字符串
// var c = 111; // number数字类型
// var d = true; // boolean (布尔类型 true(1) false(0)
// var e; // Undefined null
// console.log(e);
// 坑 引用数据类型:对象(Object)、数组(Array)、函数(Function)。
// 运算符 + - * / % ++(让变量自增+1) --(让变量自增-1)
// + 符号两边如果都是number的话会进行数学加法运算
// + 符号两边只要有一个不是number那么会进行字符串拼接
// a++ 先把变量a带入逻辑之后再让a+1
// ++a 先把变量a+1然后带入逻辑
// var a = 1;
// console.log(--a)
// console.log(++a)
// console.log(a++)
// console.log(a--)
// console.log( (a++) + (a+1) )
// console.log(a+1)
// console.log( ((a++) + (a+1)) - ((--a) + (++a)) );
// += -= *= /= %=
// var a = 1, b = 2;
// a+=b;
// a = a+b
// = 赋值
// == 值是否相等
// === 值是否相等 并且 判断数据类型是否相等
// && 两边必须都为true 才为true否则都为false
// || 只要有一个为true则为true
// var a = 1, b = 2;
// console.log(a === b);
// console.log(a * b);
// console.log(a == 1 && b<1);
// 控制语句 if switch
// if 三目运算符
// if () {}
// if (1<2) {
// console.log("if");
// } else {
// console.log("else");
// }
// 1<2 ? console.log("if") : console.log("else")
// if () {
// } else if () {
// } else if (){
// } else {
// }
// var type = "社会"
// switch (type) {
// case "社会":
// break;
// case "教育":
// break;
// default:
// break;
// }
// 数组 Array
// var arr = new Array();
// arr[0] = 1;
// arr[1] = 2;
// arr[2] = 3;
// console.log(arr[0]);
// var arr = new Array(1,2,3);
// var arr = [1,2,3,4,5,6,7,8,9,11,11,334,556];
// console.log(arr);
// 循环语句 for while forEach map
// filterfor offor inreduce
// for (var i = 0; i< arr.length;i++) {
// console.log(arr[i]);
// }
// arr.forEach( function(val, index){
// console.log(index);
// console.log(val);
// })
// while
// var i = 0
// while (i>-1) {
// console.log(i);
// i++;
// }
// var i = 0
// do {
// console.log(i);
// i++;
// } while (i<10);
// break 语句用于跳出循环。
// continue 用于跳过循环中的一个迭代。
// // 坑 无限ajax本地缓存
// for (;;) {
// console.log(111);
// }
// 对象(Object) class(类)
// 现实生活中的具体事物的封装
//
// var obj = new Object();
// obj.aaa = "哈哈哈";
// obj.ddd = "dqdwqdqw";
// obj.rrrr = "dqwdq";
// console.log(obj.aaa);
// console.log(obj['ddd']);
// var obj = new Object({
// aaa: '哈哈哈',
// ddd: 1111
// });
// console.log(obj);
// var obj = {
// aaa: '哈哈哈',
// ddd: 1111,
// 0: 111
// }
// console.log(obj);
// console.log(obj['0']);
// var arr = [
// {
// id: 1,
// list: [
// {
// title: '1111'
// }
// ]
// },
// ];
// console.log(arr[0].list[0].title);
// var car = {
// color: 'red',
// speed: '6.7s',
// start: function () {
// console.log("车启动了");
// },
// stop: function () {
// console.log("车停止了");
// }
// }
// console.log(car.color);
// car.start()
// 函数(Function)
// 作用:把具有相同功能的代码封装起来,方便下次使用
// 函数 参数
// function getName() {
// var result = 0;
// Array.from(arguments).forEach(function(val) {
// result+= val
// });
// return result;
// }
// var a = getName
// a();
// console.log(getName(10,30,40,50,60,70));
// var getName = function () {
// }
// 变量 局部作用域
// 全局作用域
// 变量提升
// function a() {
// var b = 1;
// console.log(b); // 1
// }
// a();
// console.log(b); // 1
// 闭包
// 函数内部的函数,内部函数访问外包函数的变量
// function a() {
// var x = 0;
// var add = function () {
// x += 1;
// }
// var b = function () {
// return x;
// }
// return {getValue: b,add: add};
// }
// var c = a();
// c.add()
// console.log(c.getValue()); // 1
// var e = a();
// console.log(e.getValue());
// 异步
// 同步
// 回调函数
// promise
// function a() {
// var name = null;
// return new Promise(function (success, error) {
// setTimeout(function () {
// name = "张三";
// success(name)
// }, 3000);
// })
// }
// var c = async function () {
// console.log(await a());
// console.log("11111");
// console.log("456487")
// }
// c()
// a()
// .then(function(res) {
// console.log(res);
// })
// var v = a();
// console.log(v);
// a(function(res) {
// console.log(res);
// })
</script>
</html>