1. The variables:

Used to record data that can be changed

You can declare a variable using the keyword var

Declare variables:

    varThe variable name.Copy the code

Assign a value to a variable Using an equal sign Assign the data on the right side of the equal sign to the variable on the left

Variable name = variable value;Copy the code

You can also declare multiple variables at one time to separate them

    varThe variable name1The variable name2The variable name3... ;Copy the code

Variables can be declared and assigned simultaneously:

    varVariable name = variable value;Copy the code

Variable declaration note:

I. Alphanumeric underscores cannot start with a number. $is acceptable. Cannot be keywords (the system uses such asvar if for) Reserved keyword (reserved keyword by the system) iii. The length should not exceed the maximum value255Small hump nomenclature is recommendedvar myHeight  var myAddress
Copy the code

Variable promotion:

In JS variable declarations go to the top but assignments don’t go up

Only declare variables but do not initialize (assign) the default value is undefined

console.log(output variable);varVariable name = variable value;Copy the code

The actual order of the above two lines in JS:

(1) varThe variable name. (2Console.log(output variable); (3Variable name = variable value; (assignment)Copy the code

Consider: what is the assignment of this variable when the program runs on a line?

2.JavaScript data type:

[Basic data types]

Number Number type

String String type

Boolean Indicates the Boolean type

Undefined undefined type

Null void type

[Reference data type]

Array Array type

Object Object type

Function Type

[number] Indicates the value type

Typeof determines data types

    console.log(typeof(data type));Copy the code
    var num = 123;
    console.log(typeof(num));
Copy the code

【string】 The value is a string

Enclose double or single quotation marks but the quotation marks should come in pairs

  var str1 = "Hello world";
  var str2 ="' how are you";
  console.log(typeof(str1),typeof(str2),str2);
Copy the code

【 Boolean 】 Boolean type

  var b1 = true;
  var b2 = false;
  console.log(typeof(b1),typeof(b2));
Copy the code

【undefined】 Undefined type

Undefined is not initialized or assigned

  var u1 =undefined,u2;
  console.log(typeof(u1),typeof(u2));
Copy the code

Null Indicates a null type

    var n = null;
    console.log(typeof(null));
Copy the code

【Array】 Array type (object)

The data in the array can be accessed through an index that starts at 0

  var arr =[98.63.56];
  console.log(arr,typeof(arr)); 
Copy the code

【object】 Object type (object)

Complex data types take the form of key-value pairs

Name: “zhang”

var obj = {
       name:"Pig Eight Quit".age:18.address:"Nanjing".hobby: ["Film"."Basketball"."Climb"."Programming"].wife: {name:"Miss Gao".address:"Lao Zhuang Gao".hobby: []}}Copy the code

Use the corresponding key to obtain the corresponding value in English.

    console.log(obj,typeof(obj),obj.name);
Copy the code

【function】 function type (object)

    var fun = function (){
         console.log("I'm a function");
     }
    console.log(fun,typeof(fun));
Copy the code

Function name ()

    fun();
Copy the code

Expressions:

1: Writes expressions based on conditions2: Expression manipulation (hermitage of data)3: Operation resultCopy the code

() Condition –> expression –> result –> JS basic data type — implicit conversion –> Boolean