Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Summary of JavaScript types, operators, objects, and methods


May 30, 2021 Article blog


Table of contents


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.

1, number details

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

2, string

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

3, other types (null and undefined)

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)

4, variables

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

5, operator

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

6, control structure

if()...else if()...else()

while()

do...while()

for( ; ; )/for( : )

  1. Short-circuited with: var name - o . . . o.getName();
  2. Short circuit or: var name - otherName || "default";
  3. 3-element operator: var allowed ( age > 18)? "yes" : "no";
  4. Switch statements based on a number or string can be used for multiple branches: (expressions in switch and case are compared using the strictly equal operator:)

switch(action) {

case 'draw':

drawIt();

break;

case 'eat':

eatIt();

break;

default:

doNothing();

}

switch(1 + 3){

case 2 + 2:

yay();

break;

default:

neverhappens();

}

7, the object

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