May 30, 2021 Article blog
JavaScript is an object-oriented, dynamic language that includes types, operators, standard built-in objects, and methods. I ts syntax comes from Java and C, so many of the syntax features of both languages apply to JavaScript as well. O ne of the main caveats to note is that JavaScript does not support classes, and the concept of classes is perpetuated by JavaScript through object prototypes (see Classes here for content on ES6 classes). Another major distinction is that functions in JavaScript are also objects, allowing functions to be passed like other objects while including executable code.
Javascript takes full floating-point calculation (double fine reading 64-bit) note! E
rrors occur in some operations eg: 0.1 plus 0.2 s 0.300000000000004 We can also use the built-in objects provided by JavaScriptMath, and the built-in function parseInt(); I
n addition, JavaScript also provides parseFloat(), but it only supports parsing decimal numbers in parseInto ("123", 10)//123 -- >10 means decimal
parseInt("010", 10); //10
PARSEINT ("010"); // 8 If there is no second parameter, the beginning is 0, 0x start is 16 biligers.
parseInt("0x10"); // 16
How do I convert a binary to an integer value?
parseInt("10011",2);
When the first argument is not a numeric string parseInt ("hello", 10);
NaNNaN is a special value with which any numerical calculation results are NaN
There are also two special values, Infinity and -Infinity (positive and negative), that use the built-in function isFinite () to determine whether a variable is Infinity-Infinity NaN
The string in JavaScript is a sequence of Unicode characters
Each encoding unit is represented by a 16-bit binary number. E
ach Unicode character is represented by one or two encoding units.
"hello".charAt(0); // "h"
"hello, world".replace("hello", "goodbye"); // "goodbye, world"
"hello".toUpperCase(); // "HELLO"
"hello".length; // 5
The essence of null is an empty value that must be accessed using the null keyword
Undefined is an object of an undefined type (also an object) that represents an uninitialized value, that is, a value that has not yet been assigned. (JavaScript allows variables to be declared without assigning values, and one variable that has not been assigned is the undefined type)
Boolean type: (true / false) other types convert to it
Flase, 0, " , " , NaN, null, and undefined are implicitly converted to false when JavaScript needs a Boolean variable (the others are converted to true)
Declare a variable in JavaScript with var
var a;
var name = "simon";
var a;
var name = "simon";
There is no scope in the statement block in JavaScript
JavaScript's arithmetic operators include the 、-、, /, and % -- the rest (unlike the mode operation). Assignments use the operator, and there are also compound operators, such as s and -, which are equivalent to x s x op y.
Can be used to connect strings
"3" + 4 + 5; // 345
3 + 4 + "5"; // 75
1 === true; //false
123 === "123"; // false
123 == "123" // true
1 == true; // true
if()...else if()...else()
while()
do...while()
for( ; ; )/for( : )
switch(action) {
case 'draw':
drawIt();
break;
case 'eat':
eatIt();
break;
default:
doNothing();
}
switch(1 + 3){
case 2 + 2:
yay();
break;
default:
neverhappens();
}
How objects are created:
1.var obj = new Object();
2.Var Obj = {} ---> object word
var obj = {
name:"carrot",
"for":"Max",
details:{
color:"orange",
size:12
}
}
You can use chain access:
obj.details.color;//orange
You can access it in parentheses:
obj [ detail ] [ color ];
Object type: (like a class in Java)
function Person(name,age){
this.name = name;
this.age = age;
}
Create a Person object:
var You=new Person("zhangjiahui","23");
Available You.name "ZJH"; to assign a value
Available var name-You.name; to assign a value
obj["name"] = "Simon";