Home >Web Front-end >Front-end Q&A >What is the superset of javascript

What is the superset of javascript

青灯夜游
青灯夜游Original
2021-06-09 15:04:032271browse

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.

What is the superset of javascript

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:

  • Variable names can contain numbers and letters.
  • Except the underscore _ and the dollar $ sign, it cannot contain other special characters, including spaces.
  • Variable names cannot start with a number

Syntax: var [variable name] : [type] = value;

var [data]:[string]='hello world';

Note:

  • When declaring a variable Without a valuewill default to the value: undefined
  • When declaring a variable and giving value and variable name, its type is arbitrary
  • When declaring a variablewithout giving a value and When the type is , its type is any, and the value is undefined

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:

  • Global scope Domain − Global variables are defined outside the program structure and can be used anywhere in your code.
  • Class scope − This variable can also be called a field. Class variables are declared inside a class, but outside of class methods. This variable can be accessed through an object of the class. Class variables can also be static, and static variables can be accessed directly through the class name.
  • Local scope − Local variables, local variables can only be used in a code block (such as a method) where it is declared.

TypeScript output:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What are the html5 tags?Next article:What are the html5 tags?