Preface: So why did the 1. JavaScript issuesThe main problems with JavaScript are as follows: Because the type of As follows: function sum(x, y){ return x + y } sum(100, '100') // 100100 2. Advantages of TypeScript
let num: number = 6; The variable So, the advantages of TypeScript are as follows:
3. Disadvantages of TypeScript The details are as follows:
4. TypeScript's operating environment Install Node.js and other operations to ignore The command to install TypeScript is as follows: npm install -g [email protected] Here I specify the version number through @, or you can specify no version number After installing The execution flow is as follows: # Compile TS code tsc demo.ts # After compiling, you will get the demo.js file, and then you can run it If you install the The specific steps are as follows: # 1. Global installation npm install -g [email protected] # 2. Run the code ts-node demo.ts It is worth noting that the directory after installation must be in the environment variable, otherwise an error will be reported. 5. Scope IssuesWhen we execute ts files in the project, if the same variable name exists in different files, an exception will be thrown. The sample code is as follows: a.ts let str: string = 'Hello World' b.ts let str: string = 'A bowl of Zhou' At this time, an exception will be thrown, that is, the block scope variable "str" cannot be re-declared. If the editor is VScode, a prompt will be displayed when the mouse hovers over the variable name. There are two ways to solve this problem. The first is to create an immediately executed function (an anonymous function) for each file to ensure that each file has a separate scope. The sample code is as follows: (function() { let str: string = 'A bowl of Zhou' }){} The second way is to use export to export the current file as a module. The sample code is as follows: let str: string = 'A bowl of Zhou' export {} This is the end of this article about what is TypeScript? For more related TypeScript content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Mysql tree-structured database table design
>>: The failure to play flv/MP4 and other video files on the website is related to the MIME type.
The benefits of using MySQL master-slave replicat...
Docker Compose Docker Compose divides the managed...
This article introduces the method of manually bu...
I have been learning about responsive design rece...
As a software developer, you must have a complete...
Mysql commonly used display commands 1. Display t...
In daily maintenance, threads are often blocked, ...
CSS combination selectors include various combina...
Apache Superset is a powerful BI tool that provid...
Some web pages may not look large but may be very ...
Preface Recently I encountered a requirement, whi...
Table of contents Preface 1. Conventional Vue com...
Some web pages may not look large but may be very...
The docker create command can create a container ...
For more exciting content, please visit https://g...