A: hi! ~ Hello everyone, I am YK bacteria ๐Ÿท, a microsystem front-end โœจ, love to think, love to summarize, love to record, love to share ๐Ÿน, welcome to follow me ๐Ÿ˜˜ ~ [wechat account: Yk2012Yk2012, wechat public account: ykyk2012]

“This is the 9th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

1. Variable declarations and types

Var let const difference

  1. Var is ES5 syntax, let and const are ES6 syntax
  2. Var has a variable boost
  3. Var and let are variables that can be modified. Const is a constant and cannot be modified (it can be used to define reference types)
  4. Let, const block-level scope; Var function scope
var let const
Function scope Block-level scope Block-level scope
Variable ascension There is no variable promotion There is no variable promotion
Values can be changed Values can be changed Value cannot be changed
The global declaration becomes a property of the Window object Don’t Don’t
You can repeat the declaration You cannot duplicate the declaration You cannot duplicate the declaration
You can declare it conditionally Cannot be declared conditionally Cannot be declared conditionally
The iteration variable holds the value of exiting the loop Declare a single instance per iteration Error because the value cannot be changed

ใ€ES6ใ€‘ Variable declaration -var-let-const- Distinction and connection – summary

1.2 Data Types

  • Value types: Undefined, Null, Number, String, Boolean, Symbol(ES6), BigInt(ES10)
  • Reference types: Object: Array, Function

Data types – Basic data types – Reference data types – Conversion between types – Determination of data types

1.3 The difference between value types and reference types

  • The value type is stored in stack memory, and the variable gets its value
  • The reference type is stored in the heap, and all the variable gets is a reference to it, its address

ใ€JSใ€‘JavaScript- Object- Object- Built-in Object- Host Object- Custom Object- Operation Object- Basic data type and reference data type difference

1.4 TypeOF Determines the types

  1. Undefined, string, number, Boolean, symbol, bigint
  2. Function ใ€ function ใ€‘
  3. Object, (typeof null === ‘object’)

1.5 Method for determining data types

  1. Typeof [other than null basic type + function]
  2. Instanceof [reference type] [from subclass to superclass to object]
  3. ToString () [any type]
  4. Array.isarray ()

1.6 Implement a general function to determine data types

const getType = (s) = > {
  const r = Object.prototype.toString.call(s)

  return r.replace(/\[object (.*?)\]/.'$1').toLowerCase()
}

/ / test
console.log(getType()) // undefined
console.log(getType(null)) // null
console.log(getType(1)) // number
console.log(getType('YK bacteria')) // string
console.log(getType(true)) // boolean
console.log(getType(Symbol('YK bacteria'))) // symbol
console.log(getType({})) // object
console.log(getType([])) // array
Copy the code

1.7 = = = ไธŽ = =

=== strictly compares equality

== does a cast and then a comparison

The following is true

100= ='100'
0= =' '
0= =false
fase == ' '
null= =undefined
Copy the code

Here’s a case where we can use theta = theta

if(a == null) {}
/ / equivalent to the
if(a === null || a === undefined) ()Copy the code

1.8 TRULY variables and Services variables

  • Truly variables:!!!!! a === trueThe variables of
  • Falsely variables:!!!!! b === falseThe variables of

Falsey variables are listed below, and all but six of them are Truely variables

!!!!!0= = =false!!!!!NaN= = =false!!!!!' '= = =false!!!!!null= = =false!!!!!undefined= = =false!!!!!false= = =false
Copy the code

1.9 Casting and Implicit Casting

  • Mandatory:parseInt,parseFloat,toString
  • Implicit:if, logical operation,= =,+Concatenated string

ES5 datatypes – Basic datatypes – Reference datatypes – Conversion between types – Datatypes

1.10 Statements and Expressions

Expression: An expression produces a value, which can be placed wherever a value is needed

a
a+b
demo(1)
x===y? 'a': 'b'
Copy the code

statements

if() {}for() {}Copy the code

Finally, welcome to pay attention to my column and make good friends with YK bacteria!