Home  >  Article  >  Web Front-end  >  What is javascript super

What is javascript super

藏色散人
藏色散人Original
2021-09-01 15:28:502213browse

javascript super actually refers to TypeScript, a superset of javascript. TypeScript is a free and open source programming language developed by Microsoft. It supports the ES6 standard. It can be compiled into pure JavaScript, and the compiled JavaScript can run on any computer. on the browser.

What is javascript super

The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

What is javascript super? What is a superset of javascript?

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.

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, and conversely, 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 the extension of the TypeScript code file,

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 letter.

Except the underscore _ and the dollar $ sign, it cannot contain other special characters, including spaces.

Variable name cannot start with a number

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

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

Note:

When declaring a variable When there is no value, the default value is: undefined

When a variable is declared with a value and variable name, its type is arbitrary

When a variable is declared without a value and type, its type is arbitrary , the value is undefined

If the given value does not match the type, an error will be reported.

[Recommended learning: javascript basic tutorial

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 − Global variables are defined outside the program structure, and they can be anywhere in your code. Location usage.

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);

The above is the detailed content of What is javascript super. 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