JavaScript ES6

1. The composition of JavaScript

JavaScript is an object-based, event-driven, and secure scripting language.

A complete JavaScript consists of three parts

        1.ECMAScript: It is a set of script specifications for customizing the code of conduct.

        2. DOM (Document Object Model): Document Object Model.

        3. BOM (Browser Object Model): browser object model.

2. Using JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 第一种方法:在script标签里写 -->
    <script type="text/javascript">
        document.write("你好,CN"+'<br>');
    </script>
    <!-- 第二种方法:外部javascipt文件 -->
    <script type="text/javascript" src="shoYe.js"></script>
    <!-- 第三种方法:在html标签内写JavaScript -->
    <input type="button" value="单击弹出对话框" onclick="javascript:alert('你好,JS\nok');">
    <p onclick="javascript:alert('1'==1);">伪证</p>
</body>
</html>

3. The core syntax of JavaScript

        1. Variable declaration and assignment: var variable name; var variable name list;

        2. Data type: Numeric type (number) includes floating-point numbers, string (string) includes characters, single quotes and double quotes are the same, and Boolean (boolean), and NaN (Not a Number) means not a number, it is a number type.

method of string
charAt() Returns the character at the specified position
toUpperCase() Convert a string to uppercase
toLowerCase() Convert a string to lowercase
indexOf()

Returns the position of the first occurrence of a specified string within the string

subString() Used to extract characters between two specified subscripts in a string
split() Used to split a string into an array of strings
replace() Used to replace lin'yi'xi with some characters in a string

 Special data types: empty type (null) and undefined type (undefined).

Determine the data type: typeof (value or variable);

        3. Operator: == will automatically perform type conversion, === equivalent and other types.

        4. Logical control statement: Same as Java.

        5. Comments: //, /* */

        6. Data type conversion

, (1). Convert to string type: 1.obj.toString() 2.String(obj): Special types can be converted into strings.

            (2). Convert to numeric type: 1.Number(obj); 2.parseint(); parseFloat();

            (3). Convert to Boolean type: Boolean(obj);

4. System dialog

1.alert()

method is used to display an alert dialog to the user with the specified text and an OK button. It can be used to output some uncertain data to judge the location of the error.

2.confirm()

The method is used to display a message dialog box to the user, which contains an "OK" button and a "Cancel" button. When the user clicks the "OK" button, it returns true; when the user clicks the "Cancel" button, it returns false.

3.prompt()

method will pop up a prompt dialog box, waiting for the user to enter some data. The first parameter is on the dialog box, which is usually some prompt information; the second parameter appears in the text box entered by the user and is selected as the default value.

4.console

The console object provides an interface for viewing console debugging. It may work differently on different browsers, but generally provides a common set of functions

console method
console.log() Generic method for printing content
console.error() print an error message
console.clear() Empty the console and output Console was cleared (the console is cleared)
console.timeEnd() Ends a specific timer and prints the elapsed time in milliseconds from start to finish
console.timeLog() Print the elapsed time of a specific timer
console.trace() Output a stack trace (stack trace)
console.time() Start a timer with an input parameter as a specific name, and the upper limit of timers that can run simultaneously in the display page is 10,000.
console.table() Print tabular data into a table
console.info() Print information class description information
console.dirxml() Print the specified object represented by the XML/HTML element, otherwise display the js object view
console.debug() Print a "debug" level message to the console

Summary of this chapter

There is no brilliance waiting to come out; only the beauty that comes out.

Guess you like

Origin blog.csdn.net/zouzxxi/article/details/130488308