Make writing a habit together! This is the 10th day of my participation in the “Gold Digging Day New Plan · April More text Challenge”. Click here for more details.

type

If you do a Wikipedia search for the definition of type, you’ll find that types exist in every field.

In a computer, a type confirms that a value or group of values has a specific meaning and purpose (although some types, such as abstract and functional types, may not be represented as values in a program run).

Those familiar with programming know that “HelloWorld” is a string, 1234 is a number, and true is a Boolean.

Types are fundamental to programming. JS has types, and so does other programming.

A set of types in the JavaScript language consists of primitive values and objects.

  • The original value

    (Directly represents immutable data at the bottom of the language)

    • Boolean type
    • Null type
    • Undefined type
    • Numeric types
    • BigInt type
    • String type
    • symbols
  • Object (a collection of properties)

Concepts that need special attention by extension of type include:

The type system (English: Type System) is used to define how values and expressions in a programming language are grouped into many different types, how these types are manipulated, and how these types interact.

Type checking performs verification processing and imposes type constraints, which can occur at compile time (static checking) or run time (dynamic checking). Static type checking is done in the context of semantic analysis performed by the compiler. If a language enforces a typing rule (that is, it usually only allows automatic type conversions without loss of information), this processing is called strong typing, and vice versa.

Weak type

Like VB, PHP, JavaScripJS are weakly typed languages. When you create a property or variable, you can switch the type at run time even if you assign a certain type of value.

let userName='Pinellia in the front'

userName=123
Copy the code

Strongly typed

Java, Python, and C++ are strongly typed languages that specify the type of a variable when it is defined.

Int userName=' 'Copy the code

Once the type of a variable is determined, it is always that data type unless cast.

TS is strongly typed, and once we assign a value of a particular type to a variable we create, TypeScript requires that the value remain typed.

For the above code, we rewrite it with TS:

Let userName:string=' 1 'Copy the code

Error reported in TS environment:

At the same time, you’ll notice:

Weakly typed languages do not explicitly specify the type of a variable when declaring it

Strongly typed languages must specify the type of the variable, just as in C we must use int or float if we want to define a numeric variable:

Float, f = 3.6 x, y = 5.2; int i=4,a,b;Copy the code