React 1 - Javascript (ECMAscript) re-learning

Reference: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/A_re-introduction_to_JavaScript

 

Javascript type:

 

digital:

  • JavaScript does not distinguish between integer and floating-point values, all numbers are represented by floating-point value in JavaScript, so when performing digital operations to pay special attention.

 

  • JavaScript support standard arithmetic operators , including addition, subtraction, modulus (or remainder), and a built-in objects not mentioned before  Math(mathematical objects)

 

 

  • Built-in function  parseInt() to convert the string to an integer. The second optional parameter of the function represents a group represented by the string of digital (binary)

 

  • Built-in functions  parseFloat()for string parsing float, the parseInt()difference is, parseFloat() applied only to resolve a decimal number.

 

  • Operator + cells can also be translated into a string of digital values

 

  • If the given string is not present in numerical form, the function will return a special value NaN

 

  • Built-in function  isNaN() to determine whether a variable NaN

 

 

  • JavaScript There are two special values: Infinity(positive infinity) and  -Infinity(negative infinity)

 

 

  • Built-in function  isFinite() to determine whether a variable is a finite number, if the type is Infinity-Infinity or NaN则返回false

 

 

 

  • Note: 

parseInt() And the  parseFloat() function attempts to parse the string of characters one by one, until I meet can not be parsed into a digital character, then return all the numbers before the character numeric characters.

然而如果使用运算符 "+", 只要字符串中含有无法被解析成数字的字符,该字符串都将被转换成 NaN

 

字符串:

 

  • 字符串的 length(编码单元的个数)属性,可以得到它的长度

  • 字符串也有 methods(方法)能让你操作字符串和获取字符串的信息

 

 

 

其他类型:

  • null 表示一个空值(non-value),必须使用 null 关键字才能访问
  • undefined 是一个“undefined(未定义)”类型的对象,表示一个未初始化的值,也就是还没有被分配的值。一个未被赋值的变量就是 undefined 类型。还有一点需要说明的是,undefined 实际上是一个不允许修改的常量。
  • JavaScript 包含布尔类型,这个类型的变量有两个可能的值,分别是 true 和 false

根据具体需要,JavaScript 按照如下规则将变量转换成布尔类型

 

  • JavaScript 支持包括 &&(逻辑与)、|| (逻辑或)和!(逻辑非)在内的一些逻辑运算符。

 

 

 

 变量

  • let 语句声明一个块级作用域的本地变量,并且可选的将其初始化为一个值

 

 

 

  • const 允许声明一个块级作用域不可变的常量。

 

 

 

  • var 声明的变量在它所声明的整个函数都是可见的

 

 

 

  • Note:

声明了一个变量却没有对其赋值,那么这个变量的类型就是 undefined

 

 

运算符:

  • JavaScript的算术操作符包括 +-*/ 和 %
  • 复合运算符,如 += 和 -=,++ 和 --

 

 

 

  • JavaScript 中的比较操作使用 <><= 和 >=,这些运算符对于数字和字符串都通用。
  • 由两个“=(等号)”组成的相等运算符有类型自适应的功能

 

 

 

 

 

 

 

 

 

 

  • JavaScript 还支持 != 和 !== 两种不等运算符,具体区别与两种相等运算符的区别类似

 

控制结构:

  • if...else 条件语句
  • 条件表达式的三元操作符

 

 

  • while 循环和 do-while 循环

 

  •   for 循环

 

 

 

 

 

  • && 和 || 运算符使用短路逻辑(short-circuit logic),是否会执行第二个语句(操作数)取决于第一个操作数的结果

 

  • switch 语句

 

 

 对象

  • 创建空对象:

 

  • 对象访问

 

 

 

 

数组:

  • 创建数组

 

  • 数组Length并不总等于数组中元素个数

 

  • 数组遍历

 

 

 

  不推荐,因为会遍历出数组中Array.prototype的新属性

 

 

  •  常用数组方法

 

函数:

  • 没有使用 return 语句,或者一个没有值的 return 语句,JavaScript 会返回 undefined
  • 调用函数时没有提供足够的参数,缺少的参数会被 undefined 替代。

 

 

  • 传入多于函数本身需要参数个数的参数

 

 

  • Function is actually visited the body of a function called  arguments inside the object, the object as a similar array of objects, like, includes all the parameters passed

 

 

  • The remaining parameters (Rest parameter syntax)

 

Symbol remaining parameters all the parameters will be stored behind him, without the occurrence of the previously stored. For example, function definition: AVG ( firstValue,  ... args)  , call avg (2,3,4,5), then firstvalue = 2, args = [3,4 , 5]

 

  • Rewrite function

 

 

 

 Custom objects:

  • Independent function:

  • 1 function object:

 

 

 

  • 2 function object:

Efficacy above. Disadvantages: Each time you create Person objects will create two functions

 

 

 

  • Prototype chain:

 

 

  • Internal function:

  Local global (local global)

 

 Closure:

Brought some combination of scope object is created when a function of its

 

 

  

Guess you like

Origin www.cnblogs.com/crdanding/p/12076172.html
Recommended