`
leonzhx
  • 浏览: 786725 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Chapter 1. Basic JavaScript: Values, Variables, and Control Flow

阅读更多

 

1.There are six basic types of values: numbers, strings, Booleans, objects, functions, and undefined values.

 

2.The standard describes JavaScript numbers as 64-bit floating-point values. 

 

3.One can also use “scientific” notation by adding an e, followed by the exponent of the number: 2.998e8

 

4.Calculations with whole numbers (also called integers) that fit in 53 bits are guaranteed to always be precise. (11 bits for the sign and position of dot. Ref IEEE 754)

 

5.Both single and double quotes can be used to mark strings.

 

6.Strings cannot be divided, multiplied, or subtracted. The + operator can be used on them. It does not add, but it concatenates.

 

7.typeof operator, which produces a string value naming the type of the value you give it.

 

8.Strings can be compared. The way strings are ordered is based on the Unicode standard. When comparing strings, JavaScript goes over them from left to right, comparing the numeric codes of the characters one by one.

 

9.If a program is invalid but inserting a semicolon can make it valid, the program is treated as if the semicolon is there.

 

10.The word var is used to create a new variable. After var, the name of the variable follows. Variable names can be almost every word, but they may not include spaces and they not start with a digit.

 

11.You should imagine variables as tentacles, rather than boxes. They do not contain values. They grasp them—two variables can refer to the same value.

 

12.Reserved key words of JavaScript:

abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with

 

13.Executing the code in a function is called invoking or applying it. The notation for doing this uses parentheses. Every expression that produces a function value can be invoked by putting parentheses after it.

 

14.There is a function Math.max, which takes two arguments and gives back the bigger of the two.

 

15.The function Number converts a value to a number and there are similar functions called String and Boolean that convert values to those types.

 

16.When Number is called on something like "moo", which does not contain a number, the result will be the special value NaN, which stands for “not a number.” The function isNaN is used to determine whether its argument is NaN.

 

17. In a few cases, such as the Number function, the first letter of a variable is capitalized. This was done to mark this function as a constructor. 

 

18.A variable without giving it a value and functions that do not return a specific value but are called for their side effects return an undefined value. 

 

19.The expression null == undefined will produce true.

 

20.When comparing values that have different types, JavaScript uses a complicated and confusing set of rules.  In most cases it just tries to convert one of the values to the type of the other value. However, when null or undefined occurs, it produces true only if both sides are null or undefined.

 

21.0, NaN, and the empty string count as false, while all the other values count as true.

 

22.When you do not want any automatic type conversions to happen, there are two extra operators: === and !==. The first tests whether a value is precisely equal to the other, and the second tests whether it is not precisely equal.

 

23.Values given as the condition in an if, while, or for statement do not have to be Booleans. They will be automatically converted to Booleans before they are checked. This means that the number 0, the empty string "", null, undefined, and of course false will all count as false.

 

24. If you add a nonstring value to a string, the value is automatically converted to a string before it is concatenated. If you multiply a number and a string, JavaScript tries to make a number out of the string.

 

25.NaN == NaN equals false. Checking whether a value is NaN can be done with isNaN function.

 

26.The || operator looks at the value to the left of it first. If converting this value to a Boolean would produce true, it returns this left value, and otherwise it returns the one on its right.  The && operator works similarly, but the other way around. When the value to its left is something that would give false when converted to a Boolean, it returns that value, and otherwise it returns the value on its right.

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics