Zhu Yi Day07-Introduction to the web front end [in JavaScript]

JavaScript 中

2.2 Basic syntax

1. Variable definition

Variable type variable name = variable value;

2. Conditional control

if else else if

2.3 Data type

Values, text, graphics, audio, video. . . . . .

number

No distinction between decimal and integer

String

‘abc' "abc"

Boolean value

true false

logic operation

&& || !

Comparison operation

== equal to (the type is different, the value is meaningful, and it will be judged as true)

=== Absolutely equal

null和undefined

null empty

undefined

Array

java: a series of identical objects

js: casually defined

var qwe = [1,2,3,4,'qwe',"hello"]

Object

Each attribute is separated by a comma, the last one does not need a comma

2.4 Strict inspection mode

'use strict' to prevent problems caused by randomness

3. Data type

3.1 String

1. We use single quotes and double quotes for normal strings

2. Escape character \

3. Write multi-line strings

var msg = `
    	hello
    	world
    	你好`

4. Template string

let name = "ijuy";
let age = 3;
let msg=`你好,${name}`

5. String

str.length

String variability, immutable

  • method

student.toUpperCase () case conversion

student.toLowerCase()

student.substring (1) interception

student.substring(1,3)

3.2 Array

Array can contain any data type

var arr = [1,2,3,4,5,6]

1. Length

arr.length

If the size of the array assigned to arr.length changes

2. indexOf Get subscript index by element

3. slice () intercepts a part of Array and returns a new array, similar to String's substring

4. Push (), pop () stack with open tail

5, unshift (), shift () stack of head opening

6, sort () sort

7, reverse () element reversal

8. Concat () splicing

9, join () uses a specific string connection

10. Multidimensional array

3.3 Object

Several keys

All keys are strings, all values ​​are arbitrary objects

var 对象={
    属性名:属性值,
    属性名:属性值,
    属性名:属性值
}
var person={
    name = "ijuy"
}

1. Dynamically delete attributes

delete person.name
true

//原属性name就没了

2. Dynamic addition

person.haha="haha"

3. Determine whether the attribute value is in this object

XXXX in XXXX

'name' in person

3.4 Process control

if judgment

'use strict'
var age = 3;
if(age>3){
    alert("haha");
}else{
    alert("kuwa!");
}

cycle

'use strict'
var age = 3;
while (age<100){
    age=age+1;
    console.log(age);
}

for (object in variable) iterative subscript

for (object of variable) iteration content

foreach

3.5 Map Set

Map:

<script>
var map = new Map([['tom',100],['jack',90],['haha',80]])
var name = map.get('tom');
console.log(name);
</script>

Set: Unordered and non-repetitive set

var set = new Set([1,1,1,2,1,2]);
set

Set(2) {1, 2}

3.6 Iterable

Traverse the map

var map = new Map([['tom',100],['jack',90];
for(let x of map){
    console.log(x);
}

Traverse set

var set = new Set([1,1,1,2,1,2]);
for(let x of set){
    console.log(x);
}

Guess you like

Origin www.cnblogs.com/ijuysama/p/12700037.html