This article will talk about how javascript code runs in the browser and how to run js files under windows. I hope it will be helpful to you. Don’t forget to bookmark this site.
JavaScript
ECMAScript
It is a script programming language standardized by Ecma International (formerly the European Computer Manufacturers Association) and established by ECMA-262. It specifies the core syntax of JavaScript scripts, such as data types, keywords, reserved words, operators, objects, statements and other operation symbols in Python.
B0M
It defines the interface for JavaScript to operate the browser, and provides ways to access certain functions (such as browser window size, version information, browsing history, etc.) and operation methods.
##dom
It defines the interface for JavaScript to operate HTML documents, and provides ways to access HTML documents (such as body, form, div, textarea, etc.) and operation methods.
DOM
Natural language
A carrier of information when people communicate with each other.
Machine language
The carrier of information when humans and machines communicate.
js writing and running
Two methods
1. In the web page: directly add JS code inline code piece
.
<input type="button" value="Click me to try" onclick="alert('Hello World')" />
2. Outside the web page: Use the src attribute of the tag to introduce some inline code pieces
below the external JS file.
<> alert('Hello World~!'); </>
Writing
-
js code must be written within the scope of the tag. Some are shown below:
-
document.write is equivalent to a tool whose function is to print the content between () to the big whiteboard
-
Function usage
(1)[1]document.write (print the content to the large white version);
[2]{statement = expression + semicolon; -
Usually we will write it after the html tag, in order to solve some troubles
-
Introduced through src, code cannot be added internally
-
Comment
(1)//Single line comment; // I am a line of text and I don’t want it to be executed by the JS engine, so I comment it out (2)/*Multi-line comments*/;/* Get the user’s age and name and display them through the prompt box */ (3) Selected content + //Single-line comment shortcut key ctrl + /;// Used to comment single-line text (shortcut key ctrl + /)
-
Constant: A quantity whose value cannot be changed while the program is running.
-
[1] Keyword: a word with a special meaning; [2] var: tells the compiler that the following identifier is a variable; [3] Identifier: consists of numbers, letters, underscores, $ and the first letter cannot be numbers, and secondly, do not have the same name as a library function or keyword
Simple data types in JavaScript and their descriptions are as follows
Numeric type Number JavaScript numeric type can store both integers and decimals (floating point numbers).
numeric base
The most common base systems are binary, octal, decimal, and hexadecimal.
At this stage, we only need to remember that in JS, add 0 in front of octal and 0x in front of hexadecimal.
isNaN
Used to determine whether a variable is of non-numeric type, returning true or false
var age = 21; // integer var Age = 21.3747; // decimal
// 1. Octal number sequence range: 0~7 var num1 = 07; // Corresponds to decimal 7 var num2 = 019; // Corresponds to decimal 19 var num3 = 08; // Corresponds to decimal 8 // 2. Hexadecimal number sequence range: 0~9 and A~F var num = 0xA;
String concatenation
Multiple strings can be spliced using +. The splicing method is string + any type =. The new string after splicing will convert any type added to the string into a string before splicing, and then splice into a new string. String
Boolean
The Boolean type has two values: true and false, where true represents true (true) and false represents false (false).
var strMsg = “I am a handsome and wealthy programmer!”; alert(strMsg.length); // Display 11
//1. String "Add" alert('hello' + ' ' + 'world'); // hello world //1.2 Numeric string "Add" " alert('100' + '100'); // 100100 //1.3 numerical string + Numeric alert('11' + 12); // 1112
console.log('Teacher' + 18); // As long as there are characters, they will be connected var age = 18; console.log('Teacher is age old');
// This won't work console.log('teacher' + age); //Teacher 18 console.log('Teacher' + age + 'Sui La'); // The teacher is 18 years old
When adding Boolean and numeric types, the value of true is 1 and the value of false is 0.
Undefined Null
A variable that is not assigned a value after declaration will have a default value of undefined
Literal
A literal is a representation of a fixed value in source code. In layman’s terms, a literal represents how to express this value. Numeric literals: 8, 9, 10 String literals
Quantity: Qianfeng Education’, “web full stack” Boolean literal: true, false
Data type conversion
The data obtained using forms and prompts is of string type by default. At this time, simple addition cannot be performed directly, but the data type of the variable needs to be converted.
In layman’s terms, it means converting a variable of one data type into another data type. There are usually three ways of conversion:
Convert to string type
Convert to numeric type
Convert to boolean
Operator classification
Operator, also known as operator, is a symbol used to implement functions such as assignment, comparison, and performing arithmetic operations.
Commonly used operators in JavaScript are:
Arithmetic operators Increment and decrement operators Comparison operators Logical operators Assignment operators
Increment and decrement operators
Overview of Increment and Decrement Operators If you need to repeatedly add or subtract 1 to a numeric variable, you can use the increment ( + + ) and decrement ( – ) operators to do so.
increment operator
Prefix increment operator + + num Prefix increment means incrementing by 1, similar to num = num + 1, but + + num is simpler to write. Instructions for use: add yourself first, then
return value
Postincrement operator
Post-increment of num + + means incrementing by 1, similar to num = num + 1, but num + + is simpler to write. Usage tips: return the original value first, then add it yourself
Comparison operators
Overview of comparison operators
Concept: Comparison operators (relational operators) are operators used when comparing two data. After the comparison operation, a Boolean value (true/false) will be returned as
The result of the comparison operation.
Logical operators
Logical operators overview
Concept: Logical operators are operators used to perform Boolean operations, and their return values are also Boolean values. Later, it is often used to judge multiple conditions in development.
Assignment operator
Concept: Operators used to assign data to variables
reserved words
Reserved words: They are actually reserved “keywords”, which means that although they are not keywords now, they may become keywords in the future, and they cannot be used as variable names.
or method name.