What do you think is the difference between typescript and javascript? What types have you used in typescript-the difference between type and interface in typescript

  • What do you think is the difference between typescript and javascript
  • What types of typescript have you used
  • The difference between type and interface in typescript
    Your answer: ## What do you think is the difference between typescript and javascript
    • Different type characteristics
    • JavaScript type system characteristics-weak and dynamic types
    • Typescript type system characteristics-strongly typed and statically typed
    • Data in TypeScript requires a clear type, JavaScript does not require
    • TypeScript is finally converted into JavaScript to run
    • supplement
    • Type safety perspective
    • Strong Type: In a strongly typed language, arbitrary data implicit type conversion is not allowed (it is not allowed at compile time, it does not mean that an error is reported during execution)
    • Weak type: Weakly typed languages ​​allow arbitrary data implicit type conversion
    • Type check angle
    • Static type: When a variable is declared, its type is clear. After the declaration, its type is not allowed to be modified. Statically typed languages ​​need to be type checked at the compilation stage
    • Dynamic type: The variable type can be clarified at the runtime, and the type of the variable can be changed at any time (the variable of the dynamic type language has no type, and the value stored in the variable has a type)

    What types of typescript have you used

    • basic type
    1. string, number, booleanThree types of null values can not be set in strict mode, a null value may be set in a non-strict mode, i.e., in the tsconfig.jsonfile strictor the strictNullChecksvalue can not betrue
    2. void: It can only be undefinedin strict mode, and it can also be stored in non-strict modenull
    3. undefinedwithnull
    • Object type
    1. Object type
    2. Array type
    • Function type, arbitrary type, interface

    The difference between type and interface in typescript

    Same point

    1. Can constrain objects and functions
    2. Both allow extension, and the two can also extend each other

    difference

    • The declaration and extension syntax of type and interface are different
    • type can declare the basic type name, such as string, interface cannot
    • The declaration of the same name of the interface can be combined, but the type cannot, and an error will be reported: Duplicate identifier'person'

Guess you like

Origin blog.csdn.net/weixin_40599109/article/details/108624610
Recommended