0. Preface
Recently, I just finished the last section of the work, the results immediately began a new round of work, to express innocence, (O′?ェ ' O), the program Ape is really a dead tired people work.
This evening to see colleagues new unsealed JavaScript authoritative guide, the whim of thinking, if I can put the focus of the book and specific knowledge points out, then later people can not take a few detours?
Holding this idea, so began this evening's book tour, but also because of small series like to organize things this habit, only this article.
Sincerely hope to see this article of you, can feel the small make up that deep love! ~
Grammatical structure of the 1.JavaScript grammar core
1.1 Character Set 1.1.1 case sensitive
Keywords, variables, function names, and all identifiers are all in a consistent case
It is important to note that HTML is not size-sensitive, and some of the HTML names or property names in JavaScript must be lowercase
1.1.2 spaces, line breaks, and format controls
Spaces between tokens in the program are ignored in JavaScript
Our interface can be specific to the specific content of the code indentation, so to ensure that the interface
Readability and aesthetics
1.2 Notes
Support for annotations in two formats
The "//" content after the end of the line can be ignored as a JavaScript comment
The content between "/" and "/" is also used as a comment
- Can write across lines
- But internal annotations cannot be nested
1.3 Direct Volume
Data values directly used in the program
Number 12
Decimal 0.12
string literal "Hello World"
Another string ' Hi '
Boolean value True
Another Boolean value of False
Direct amount of regular expression (used as pattern match)/javascript/gi
8. NULL NULL
9. Special Direct Volume
- Object {X:1,y:2}
- Array {* * *}
1.4 Identifiers and reserved words
The identifier is a name.
In JS, identifiers are used to name variables and functions, or to be used as a marker for jumping positions in some loop statements in JavaScript code
Naming conventions
You must start with the following:
Letters
Underline (_)
Dollar symbol ($)
1.5 Reserved words
Names are not arbitrarily named,
Because some of the names in the program are already occupied by the system.
For example
breakclassifelsewhile...
1.5 Optional semi-colons
, you can split the statement to enhance the readability and cleanliness of the statement,
But if there is no proper segmentation of the sentence, it will result in disastrous consequences.
想象中正确的解析方式 var y = x + f (a + b).toString()实际的解析方式 var y = x + f(a + b).toString()
There are some old programmers who like to start with a semicolon at the beginning of every sentence,
The advantage of this is that no matter how the previous sentence is done,
The current sentence can be correctly analyzed.
2.JavaScript syntax core types, values, variables 2.1 JavaScript data types are divided into two three ways of partitioning
First Kind
原始类型 数字 字符串 布尔值 特殊的原始类型 null undefined 代表了各自特殊类型的唯一成员对象类型 对象是属性的集合,每个属性都由 “名/值对” 值可以是原始值,如数字,字符串,也可以是对象 存在一个特殊的对象----全局对象
The second Kind
拥有方法的类型不能拥有方法的类型
Third Kind
可变类型 对象 数组不可变类型 数字 布尔值 null undefined
2.2 Numbers
In JavaScript, integers and floating-point numbers are not distinguished, and all digits are represented by floating-point numbers.
When a number appears directly in a JavaScript program, we call it a digital direct quantity.
2.2.1 Integer Direct volume
十进制 100000十六进制 0x** 0X**八进制 不支持使用 能够通过取巧实现 0377 -> 3 * 64 + 7 * 8 + 7 = 255
2.2.2 Floating-point Direct volume
Floating-point direct quantities can contain decimal points
You can also use exponential notation to represent floating-point direct quantities
在实数后跟数字 e 或者 E 6.02e23 //6.02 * 10 ^ 23 1. 4738223E - 32 //1.4738223 * 10 ^ -32
Arithmetic operations in 2.2.3 JavaScript
Base operator
+-*/%…
Complex operators
The functions and constants defined by the properties of the Math object are implemented
Math.round(.6) //1.0:四舍五入Math.ceil(.6) //1.0 向上取整Math.floor(.6) //0.0 向下取整Math.abs(-5) //5 绝对值Math.max(x,y,z) //返回最大值Math.min(x,y,z) //返回最小值Math.random() //生成一个大于0,小于 1.0 的伪随机数Math.PI //π 3.141592673
Special cases of arithmetic operations in 2.2.4 JavaScript
Overflow (overflow)
The result of the operation exceeds the maximum number that JavaScript can represent.
Underflow (underflow)
The result of the operation is infinitely close to 0 and is smaller than the minimum value that JavaScript can represent.
Divisible by zeros
Under normal condition
Return to infinity or-infinity
0 divided by 0.
Meaningless, will get NaN (not-a-number)
In addition, infinity is divided by infinity, which is the root of a negative number, and the arithmetic operator returns NaN when used with an operand that is not an arithmetic operator or that cannot be converted to a number.
These three cases do not make an error.
2.2.5 Binary Floating-point and rounding errors
The numbers in JavaScript are accurate enough, but occasionally they can cause some problems.
var.3.2; /*三十美分减去二十美分*/var.2.1; /*二十美分减去十美分*//*false*/x==.1 /*false*/y==.1 /*true*/
Cause: 0.3-0.2 = 0.09999999999999999998 under real-world operating conditions
2.2.6 Date and time
The Date () constructor is included in JavaScript
Used to create an object that represents a date and time
For example
varthen =New Date( .,0,1);//January 1, 2011varthen =New Date( .,0,1, -,Ten, -);//January 1, 2011 local time 5:10:30pmvarnow =New Date();//Current date and timevarelapsed = Now-then;//Date subtraction, the number of milliseconds to calculate the time intervalLater.getfullyear ()//2011Later.getmonth ()//month starting from 0 countingLater.getdate ()//number of days to count starting from 1Later.getday ()//Get Day of the week, 0 means Sunday, 5 means week 1Later.gethours ()//local timeLater.getutchours ()//Use UTC to indicate hours, based on time zone
Today's reading notes are first written here, because it has been July 11, 2016 22:36:18, I also need to go home to sleep, the next article update time is not sure, anyway, there must be time to update.
Finally wish each small partner work smoothly! ~
Sapo roll to seek praise! ~ The clatter! ~
Reading notes----JavaScript authoritative guide (i)