From 2c861f9db2765e2b672da50e1ac55b82c497cce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=96=E6=B6=9B?= <2124876211@qq.com> Date: Sun, 16 Oct 2022 19:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=97=E4=B8=96=E6=B6=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.10.14\344\275\234\344\270\232.html" | 85 +++++ .../2022.10.14\347\254\224\350\256\260.md" | 360 ++++++++++++++++++ 2 files changed, 445 insertions(+) create mode 100644 "23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.14\344\275\234\344\270\232.html" create mode 100644 "23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.14\347\254\224\350\256\260.md" diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.14\344\275\234\344\270\232.html" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.14\344\275\234\344\270\232.html" new file mode 100644 index 0000000..b868717 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.14\344\275\234\344\270\232.html" @@ -0,0 +1,85 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.14\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.14\347\254\224\350\256\260.md" new file mode 100644 index 0000000..ff0337e --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.14\347\254\224\350\256\260.md" @@ -0,0 +1,360 @@ +## 基本数据类型 + +#### 基本数据类型 + +##### Number - Integer,float + +##### Boolean + +##### Null + +##### Undefined + +##### Symbol + +##### String + +​ 1.**字符串转义** + +```js +\n:换行 +\t:Tab键 +\\:斜杠 +\':单引号 +\":双引号 +``` + +​ **2.字符串下标** + +![](https://gitee.com/snailclass/tuchuang/raw/master/img/string_indexes-2022-10-709:26:49.png) + +​ 第一个元素: string[0] 最后一个元素: string[string.length-1] + + + +​ **3.String常用方法** + +```javascript +let js = 'JavaScript' +//1)获取字符串的长度: js.length + +//2)将英文字母全转为大写: js.toUpperCase() +//2.1)将英文字母全转为小写: js.toLowerCase() + +//3)截取字符串:substr(startIndex,counts) startIndex:起始索引位置 counts:截取字符串的个数 +//3.1)截取字符串:substring(startIndex,endIndex) startIndex:起始索引位置 endIndex:截止索引位置(不包含) + +//4)拆分字符串: split() +var string = 'life is now'; + +//5)去除开头或者结尾的空格: trim() + +//6)查看是否字符串中是否包含includes() indexof() +``` + +## 数据类型转换 + +#### 1.显示类型转换 + +- #### Number(mix) + +- #### parseInt(str, radix) + +- #### parseFloat(string) + +- #### String(mix) + +- #### toString(radix) + +- #### Boolean() + +**练习:将10110110转成16进制** + + + +#### 2.隐式类型转换 + +- isNaN() --> Number() +- ++/-- +/-(一元正负) +- + +- -*/% +- && || ! :()&&() --Boolean +- < > >= <= +- == != + +## 常用类 + +#### 1.Math + +1. 求最值Math.min() Math.max() +2. 舍入 Math.ceil() Math.floor() Math.round() + +#### 2.Random + +#### 3.Time + +![](https://gitee.com/snailclass/tuchuang/raw/master/img/date_time_object-2022-10-920_27_00-2022-10-1409:19:01.png) + +## 引用类型 + +#### 数组(Array) + +##### 1.创建数组 + +```javascript +//1.1创建空数组 +//使用数组构造器 +const arr = Array() +const arr = [] + +//1.2 带元素数组 +const numbers = [0, 3.14, 9.81, 37, 98.6, 100]; +const fruits = ['banana', 'orange', 'mango', 'lemon'] +const arr = [ + 'Asabeneh', + 250, + true, + { country: 'Finland', city: 'Helsinki' }, + { skills: ['HTML', 'CSS', 'JS', 'React', 'Python'] } +] +//使用字符串的split方法创建数组 +let js = 'JavaScript' +const charsInJavaScript = js.split('') +``` + +##### 2.修改数组的元素 + +```javascript +const numbers = [1, 2, 3, 4, 5] +numbers[0] = 10 +numbers[1] = 20 +``` + +##### 3.数组中常用的方法 + +```javascript +//获取数组长度 length + + +//concat:将两个数组合并在一起 +const firstList = [1, 2, 3] +const secondList = [4, 5, 6] +const thirdList = firstList.concat(secondList) + +//indexof:查找数组的元素,返回-1表示不存在,与之相同的查找方法还有includes,lastindexof + +//toString():将数组转成字符串 + +//join():添加指定字符后转成字符串 转成json常用 + +//slice():表示切片,参数个数:0 1 2 返回一个数组对象 + +//splice(): 接收 0 2 多 个参数 表示移除,替换元素 + + +//数组的添加元素:push unshift +//数组的删除元素: shift pop + +//reverse() :反转 +//sort() + +//forEach():数组为每个数组元素调用一次函数(回调函数)。 +//map() +//filter():匹配符合条件的元素 +//reduce(): 汇总数据,返回是一个数据 +//every():检查所有数组值是否通过测试 +``` + +#### 二维数组 + +```javascript +const arrayOfArray = [[1, 2, 3], [1, 2, 3]] +``` + + + +## 函数 + +#### 一、函数声明 + +```javascript +//声明 +function functionName() { +} +//调用 +functionName() +``` + + + +#### 二、函数类型 + +##### 1.无参无返回 + +```javascript +function square() { + let num = 2 + let sq = num * num + console.log(sq) +} + +square() +``` + +##### 2.无参有返回 + +```javascript +function printFullName (){ + let firstName = 'Asabeneh' + let lastName = 'Yetayeh' + let space = ' ' + let fullName = firstName + space + lastName + return fullName +} +console.log(printFullName()) +``` + +##### 3.带1参有返回 + +```javascript +function areaOfCircle(r) { + let area = Math.PI * r * r + return area +} +``` + +##### 4.带参返回多个值 + +```javascript +function printFullName(firstName, lastName) { + return `${firstName} ${lastName}` +} +console.log(printFullName('Asabeneh', 'Yetayeh')) +``` + +##### 5.带不确定个参数 + +```javascript +function GetSum() { +// console.log(arguments); +let sum = 0 +for(var i = 0 ; i 4 + +//自调用函数 +//不带返回 +(function(n) { + console.log(n * n) +})(2) +//带返回 +let squaredNum = (function(n) { + return n * n +})(10) + +console.log(squaredNum) +``` + +#### + +#### 四、箭头函数(Arrow Function) + +##### 使用方式 + +**1.如果箭头函数不需要参数或者需要多个参数,就可以使用一个圆括号的代替参数部分** + +**2.如果只有一个参数,那么可以省略圆括号** + +**3.如果函数体中只有一句代码,那么可以省略大括号** + +**4.函数中只有一个return语句时,可以省略return** + +**5.如果箭头函数返回一个对象,那么需要在对象外面加上圆括号** + + + + + +#### 五、自带默认值函数 + +有时我们将默认值传递给形参,当调用函数时,如果不传递实参,则使用默认值。函数声明和箭头函数都可以有一个或多个默认值。 + +```javascript +function functionName(param = value) { + //codes +} + +// Calling function +functionName() +functionName(arg) +``` + + + + + +#### 练习 + +```javascript +var text = +'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' +//将上述字符串去除标点空格后统计有多少个单词 +``` + +```javascript +const arr = [3,2,1,4,5] +let temp = arr[2] +arr[2] = arr[0] +arr[0] = temp +将数组中的 元素1 与 元素3 调换位置 +``` + +```javascript +const arr = [87,85,74,70,65,59,43] +1.移除第一个元素87,并在开头添加 元素86 +2.移除最后一个元素43, 并在末尾添加1 +3.在 70 65 之间插入 元素 68 +4.删除元素65 +5.使用map返回一个新的数组new_arr,要求新数组new_arr比原来数组大2 +6.筛选数组new_arr返回new_arr1,要求new_arr1: 能被2整除 +``` + + + +​ + +```javascript +使用冒泡排序: [90,65,78,66,48,39,92,73] 使用数组解构 +``` + +```javascript +将数组的单词全转为大写,要求 使用箭头函数 +const countries = ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland'] +``` + +https://leetcode.cn/problems/longest-common-prefix/ + +https://leetcode.cn/problems/merge-two-sorted-lists/ -- Gitee