JS is sensitive to case,JS ignores extra spaces
The JS variable starts with a letter, can also start with $ and _, and is also sensitive to case
VAR is used to declare variables, and ES6 's notation uses let (different browsers do for ES6 support, want to make sure that the run needs to be translated into es5, but ES6 is a trend)
var aaa = "AAA"; var Aaa= "AAA"; Console.log (AAA,AAA); // AAA AAA
A statement can declare multiple variables and use [,] to separate them.
var aaa = "AAA", AAA = "AAA";
If the declared variable is assigned, the default is undefined
var Bbb;console.log (BBB); // undefined
JS has variable promotion, var or function keyword declaration of variables and functions, will be compiled prior to compiling, and then to assign value
Console.log (CCC); var CCC = "CCC"; // the upper and lower parts are equivalent var = "CCC";
The variable in JS has a dynamic variable type, which is based on the value you give to determine whether the variable is a string, a number, a Boolean, an array, an object, a Null, a Undefined(only these kinds of variables in JS )
var x // x is undefinedvar x = 6; // x is a number var x = "Bill"; // x is a string
You can empty a variable by setting the value of the variable to null.
JS will split the code (not recommended).
document.write ("Hello world!" );d ocument.write (// this error
JS Object
In JS all things are objects, even strings, numbers, arrays are objects. Different objects have different "properties" and "methods"
You can generally use theobjectName. PropertyName"to query one property of an object. The following example contains the message as a string object, with the Length property by default
var message= "Hello world!" ; Console.log (message.length); // A
You can generally use theobjectName. MethodName () "To invoke one of the methods of an object. The following example contains the message as a string object, and the touppercase method is called to convert it to uppercase
var message= "Hello world!" ; Console.log (Message.touppercase ()); // HELLO world!
JS function
The JS function has the following four ways of declaring, where the first is the second equivalent, the third can use both func3 and FUNC4 calls, and the fourth is to declare the variable type as function directly using the constructor
function Func1 (num1,num2) { // do something Arguments} var func2 = function
(num1,num2) {
//
Do something
}
var func3 =
function
Func4 (num1,num2) {
//
do something
}
var func5 =
new Functon ();
JS can declare an anonymous function (usually only once), declare it without declaring formal parameters, and use the arguments array to get the passed arguments (although the arguments array has the length property, but there are no other methods owned by the normal array)
The JS function can use return to specify the returned value, which defaults to undefined. Return is often used to interrupt and eject function execution.
Variables declared by Var, const, or let in the JS function are local variables that are destroyed at the end of the function call (the case is "closed"), but if an undeclared variable is assigned directly, the variable is a global variable.
JS operator
+ 、-、 *,/,% (remainder), + + (cumulative) 、--(decrement)
= (Assignment), + = (x+=y equivalent to x=x+y),-=, *=,/=,%=
※ using "+" for Strings is a string concatenation operation, and if the number and string use "+" then the default string concatenation
Comparison and logical operators: = = (judging if the values are equal), = = = (also judging if the value is equal to the data type) "Specific reference link",! = (not equal to), >, <, >=, <=, && (with), | | (OR),! Non-
JS Loop
If, If...else, If...else if...else If ... The most basic and most common criteria for judging
Switch...case ... case...default ... Use break interrupts at the end of each case selection to prevent over-judging; Use default to set events without any case matching. But this approach is currently used less
For Loop, JS is the most commonly used loop mode
for (statement 1; Statement 2; statement 3) {Loop code}
Statement 1: The initial value of the loop start; Statement 2: The condition is fulfilled, the loop is executed, and the sentence 2 is determined every time the loop code is executed; Statement 3: Execute statement 3 after the Loop code execution, generally used to judge the recursive loop value for statement 2
Statement 123 is not really necessary, and statement 1 can also set multiple values. Statement 2 can also be discarded under special circumstances, but it is necessary to break the loop by adding breaks in the loop code, or the loop may be indefinitely causing the program to crash.
For...in used to iterate through properties in an object
var obj = { name:123, age :456 } for (var inch obj) { + ":" + obj[abc]); // name:123//age:456 }
While loop, currently using less
Do...while, perform once and then condition judgment
In any of the loop statements of JS, you can use "break" to terminate the loop and use "continue" to skip one iteration in the loop. (Break through the tag reference, can actually jump out of the JS block of arbitrary code, but not commonly used)
JS Basic Finishing