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.
Table of contents 1. When inserting or modifying ...
Page replacement algorithm: The essence is to mak...
What is a file system We know that storage engine...
Use runlike to view the docker run startup parame...
Preface There are many ways to center horizontall...
Table of contents 1. Introduction to the basic fu...
Table of contents 1. Check whether MySQL has been...
Of course, there are many people who hold the oppo...
question Recently, when I was completing a practi...
1. Principle of Hotlinking 1.1 Web page preparati...
CSS adds scrolling to div and hides the scroll ba...
Preface I have read many similar articles before,...
Table of contents Install: 1. Basic use of firewa...
Demand: This demand is an urgent need! In a subwa...
Table of contents Creating OAuth Apps Get the cod...