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.
Previously, we knew several attributes of backgro...
RedHat6.5 installation MySQL5.7 tutorial sharing,...
Preface This article mainly introduces the analys...
This article shares the specific code of js to re...
After pressing Enter on the webpage, the form is a...
Table of contents Mind Map Simple understanding E...
This article shares simple HTML and music player ...
When designing H5 layout, you will usually encoun...
Table of contents Join syntax: 1. InnerJOIN: (Inn...
1: readonly is to lock this control so that it can...
Table of contents 1. Select database USE 2. Displ...
This article is used to record the installation o...
1. Install MySQL database ① Download and unzip an...
html , address , blockquote , body , dd , div , d...
Large Text Data Types in Oracle Clob long text ty...