The basic concepts of JavaScript (ii)

EDITORIAL: Today focuses on two things: JS identifiers and data types

A  variable and constant

         Before introducing the identifier is necessary to first understand what JS variables and constants.

         Variables : memory operable to temporarily store data during program execution.

    Statement way:

           var: function scope variables declared in advance, the statement may be repeated, after the foregoing statement coverage.

           let: block-level scope, the statement does not advance, can not be repeated declarations.

           const: declare a constant, block-level scope, the statement does not advance, can not be repeated declaration that is to be assigned, the assignment can not be repeated.

         Constant : can not be changed during program operation.

 

Two JavaScript identifier

  Meaning : the identifier is essentially a string of JS. But not necessarily the string identifier.

  Effect : the variable identifier is used to the like-named functions.

  Rules :

         1, can only consist of numbers, letters, underlined and $ symbol.

         2, can not start with a number

         3, case sensitive

         4, using the specific meanings of the word, verb and noun combination.

         5, follow the small hump nomenclature, that the first letter of the first word lowercase, uppercase first letter of the other.

         6, you can not use JS reserved words and keywords.

  JS keyword list is as follows:

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

Three JavaScript Data Types

         1 classification

  JS data is divided into two categories: basic data types and complex data types.

       Basic data types:

                   String (String): a plurality of ordered sequence of characters, and causes to the double or single quotes.

                   Number (number): JS does not distinguish between integers and floating-point numeric type variable declaration.

                   Boolean (Boolean): only two values: true or false. For true or false.

                   Undefined (undefined): Indicates the variable is not declared.

                   Null (empty): variable has been declared, but its value is Null.

                   Symbol (unique identification): ES6 added.

  Complex data types:

                   Object (Object): JS in anything can be seen as an object.

       According to how data is stored may be divided into two categories: primitive value and reference value. Specific fact the same as above.

          Original values: simple data segment stored on the stack (Stack) in, say, the position thereof is stored in the variable values ​​directly accessed.

          Reference value: objects stored in the heap (heap), that is, the value stored in the variable is a pointer (Point), pointing to memory at a storage object. 

      

 

2, the detection

         JS data type detection method is typeof.

         Use typeof detection data is returned at 7 kinds of data types, note that they are returned as a string:

                   ‘’string‘’;

                   ‘’number‘’;

                   ‘’boolean‘’;

                   ‘’undefined‘’;

                   ‘’object‘’;

                   ‘’function‘’;

                   ‘’symbol‘’;

下面是一些简单的例子:

 1 typeof "hello";//"string"
 2 typeof 123;//"number"
 3 typeof true;//"boolean"
 4 typeof undefined;//"undefined"
 5 function fn(){}
 6 var obj = new Object();
 7 var syb = new Symbol();
 8 typeof fn;//"function"
 9 typeof obj;//"object"
10 typeof syb;//"symbol"
11 typeof null;//"object",因为null最初被设计是用来当做空对象的占位符的

 

另外,有两个特别的数字:NaN(not a number不是一个数字)和infinity(无穷)。

NaN需要用Number.isNaN()检测;如果参数不是数字则返回true,是数字则返回false;

另一个方法Number.isFinite();如果参数是NaN或者infinity则返回false,否则返回true。

Guess you like

Origin www.cnblogs.com/ruhaoren/p/11320439.html