What is typescript? Introduction to typescript basic types
The content of this article is about what typescript is? The introduction of the basic types of typescript has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Overview
Javascript is a weakly typed language. Weak typing is very arbitrary and flexible. This is its advantage and also its disadvantage; the same variable , it can be either a numeric type, a string type, or various other object types. In js, if you are given a variable name, can you determine its type at a glance? I am afraid that in most cases, you Not sure, even if a number is assigned to it at the beginning, how do you know that the intermediate code will not change it into other types.
Strong type and weak type
First of all, let us briefly distinguish between strong type and weak type language. Of course, js is a veritable weak type language
Strong type
Given a variable, you must first declare its type int a; Of course, you can also assign an initial value to it at the same time, int a = 1;. If we assign a value to it later, we can only assign it to an integer type, a = 2;. If you want to assign it a string type, such as a = "xxx";, the compiler will directly report an error to you, so let's talk about it. There is no follow-up process.
Weak type
Weakly typed languages do not have these restrictions
Let’s get to the point
typescript
Typescript is a superset of javascript. It is fully compatible with javascript, but it also extends many functions. I believe you will fall in love with it after understanding it. Why do you say this? Because given you an object, you can use The editor can only prompt you to see what properties, methods, etc. are in it, without having to look for definitions everywhere. The official website of typescript is here
The form of declaring variable type is var a: Type, Type is the type. Once the Type type is declared, subsequent a can only receive the Type type and cannot receive other types, because the editor will The smart reminder you give will of course give you an error when compiling.
Basic types
Basic types include number, string, boolean, undefined, null
var v1: number = 1 var v2: string = 'hello' var v3: boolean = true var v4: undefined = undefined var v5: null = null
Array type
// 字串数组 var arr_s: string[] = ['xxx', 'yyy'] // 数字数组 var arr_n: number[] = [1, 2]
Enumeration
enum Gendar { male, female } var g: Gendar = Gendar.male
Universal type
any is equivalent to not declaring any type
var a: any = 123
The above is the detailed content of What is typescript? Introduction to typescript basic types. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JavaScript does not provide any memory management operations. Instead, memory is managed by the JavaScript VM through a memory reclamation process called garbage collection.

Question: How to use require to dynamically introduce static resources such as images in a Vue3+TypeScript+Vite project! Description: When developing a project today (the project framework is Vue3+TypeScript+Vite), it is necessary to dynamically introduce static resources, that is, the src attribute value of the img tag is dynamically obtained. According to the past practice, it can be directly introduced by require. The following code: Write After uploading the code, a wavy line error is reported, and the error message is: the name "require" cannot be found. Need to install type definitions for node? Try npmi --save-dev@types/node. ts(2580) after running npmi--save-d

How to implement data type conversion function in TypeScript using MySQL Introduction: Data type conversion is a very common requirement when developing web applications. When processing data stored in a database, especially when using MySQL as the back-end database, we often need to convert the data in the query results to the type we require. This article will introduce how to use MySQL to implement data type conversion in TypeScript and provide code examples. 1. Preparation: Starting

Overview of how to use Redis and TypeScript to develop high-performance computing functions: Redis is an open source in-memory data structure storage system with high performance and scalability. TypeScript is a superset of JavaScript that provides a type system and better development tool support. Combining Redis and TypeScript, we can develop efficient computing functions to process large data sets and make full use of Redis's memory storage and computing capabilities. This article will show you how to

How to declare a type with field name enum? By design, the type field should be an enumeration value and should not be set arbitrarily by the caller. The following is the enumeration declaration of Type, with a total of 6 fields. enumType{primary="primary",success="success",warning="warning",warn="warn",//warningaliasdanger="danger",info="info",}TypeSc

Changes in Vue3 compared to Vue2: Better TypeScript type inference Vue is a popular JavaScript framework for building user interfaces. Vue3 is the latest version of the Vue framework, with a lot of improvements and optimizations based on Vue2. One of them is improvements in TypeScript type inference. This article will introduce the improvements in type inference in Vue3 and illustrate them through code examples. In Vue2, we need to manually configure the Vue component

Title: Developing Scalable Front-End Applications Using Redis and TypeScript Introduction: In today’s Internet age, scalability is one of the key elements of any application. Front-end applications are no exception. In order to meet the growing needs of users, we need to use efficient and reliable technology to build scalable front-end applications. In this article, we will introduce how to use Redis and TypeScript to develop scalable front-end applications and demonstrate its application through code examples. Introduction to Redis

With the continuous development of JavaScript, front-end engineers have gradually become aware of some problems in JavaScript itself, such as the lack of type checking and modularity, which often cause confusion and errors in large projects. In order to solve these problems, TypeScript came into being and became an increasingly popular language in front-end development. In the field of back-end development, PHP has always been an extremely popular scripting language. Therefore, combine TypeScript to develop PHP applications
