js bottom layer

typeof return value

typeof can determine the basic data types, such as number, string, boolean, undefined, function, object and Symbol 7 types.

The data type of the reference data is imperfect, such as array and null types, and typeof is judged to be object.

Null and Array return object and
use an undefined variable will report an error, but typeof detects a variable data type will not report an error, return undefined

Note: typeof can only distinguish value types


The difference between basic data types and reference types

(1) The storage location is different

Variables of value type will be stored in the stack memory. If a variable of value type is declared in a function, the variable will be automatically destroyed when the function is executed
. The variable name of the reference type will be stored in the stack memory, but the value of the variable will be Stored in the heap memory, the variable of the reference type will not be automatically destroyed. When there is no reference variable to refer to it, the system's garbage collection mechanism will reclaim it
(2) The copy method is different

The direct assignment of a value type variable is a deep copy. For example, var a = 10; var b = a; then the value of a is copied to b. Modifying the value of b will not affect
the variable of a reference type. Direct assignment is actually a pass-by reference. Just a shallow copy

Data type verification


String splicing

Use the plus operator

The easiest way to concatenate strings is to use the plus operator.

Use concat() method

Use the string concat() method to add multiple parameters to the end of the specified string. There is no limit to the type and number of parameters of this method. It will convert all the parameters into strings, and then connect them to the end of the current string in order and finally return the connected string.
The concat() method does not modify the value of the original string, and the operation is similar to the concat() method of the array.

Use join() method

In a specific operating environment, you can also use the join() method of an array to connect strings, such as HTML string output.


Logical operators in Js

There are three logical operators in JavaScript, && and, || or,! NOT. Although they are called logical operators, these operators can be applied to any type of value, not just Boolean values, their results It can also be of any type.


Deep copy

Deep copy

Recursion

Guess you like

Origin blog.csdn.net/weixin_53687450/article/details/114867651