The superset of javascript is TypeScript. TypeScript is a free and open source programming language developed by Microsoft that supports the ES 6 standard. Its design goal is to develop large-scale applications. It can be compiled into pure JavaScript, and the compiled JavaScript can run on any browser.
The operating environment of this tutorial: Windows 7 system, TypeScript version 4, Dell G3 computer.
TypeScript Introduction:
1. TypeScript is a superset of JavaScript and supports the ECMAScript 6 standard.
Superset: If every element in a set S2 is in the set S1, and the set S1 may contain elements that are not in S2, then the set S1 is a superset of S2. set, in turn, S2 is a subset of S1. S1 is a superset of S2. If there must be elements in S1 that are not in S2, then S1 is a true superset of S2, and conversely S2 is a true subset of S1.
2. TypeScript is a free and open source programming language developed by Microsoft.
3. TypeScript is designed to develop large-scale applications. It can be compiled into pure JavaScript, and the compiled JavaScript can run on any browser.
TypeScript operation:
We can use the tsc command to execute TypeScript related code
Usually we use .ts as TypeScript code file extension,
Then execute the following command to convert TypeScript into JavaScript code:
tsc test.ts
At this time, a test.js file will be generated in the current directory (the same directory as test.ts) .
Use the node command to execute the test.js file
$ node test.js
TypeScript variable declaration:
TypeScript variable naming rules:
Syntax: var [variable name] : [type] = value;
var [data]:[string]='hello world';
Note:
If the given value does not match the type, an error will be reported.
Basic type:
1. Any type any: A variable declared as any can be assigned a value of any type.
2. Number type number: double precision 64-bit floating point value. It can be used to represent integers and fractions. A series of characters, using single quotes (') or double quotes (") to indicate the string type. Backticks (`) to define multi-line text and embedded expressions.
let data: number = 6;
3. String type string: A character series, using single quotes (') or double quotes (") to represent the string type. Backticks (`) are used to define multiline text and inline expressions.
let name: string = "ipad"; let years: number = 5; let words: string = `今年是 ${ name } 发布 ${ years + 1} 周年`;
4. Boolean type boolean: represents logical values: true and false.
let flag: boolean = true;
5. Enumeration enum: Enumeration type is used to define a collection of values.
enum Color {Red, Green, Blue}; let c: Color = Color.Blue; console.log(c); // 输出 2
6. void void: used to identify the type of method return value, indicating that the method has no return value.
function hello(): void { alert("Hello Runoob"); }
7. null null: Indicates that the object value is missing.
8. undefined undefined: used to initialize variables to an undefined value
9. never never: never is a subtype of other types (including null and undefined), which means never The value that appears.
Variable scope:
TypeScript has the following scopes:
TypeScript output is used the same as JavaScript: console.log();
var [ename]:[string]='小明'; var [age] : [number] = 10; console.log(ename); console.log(age);
For more programming-related knowledge, please visit: programming video! !
The above is the detailed content of What is the superset of javascript. For more information, please follow other related articles on the PHP Chinese website!