Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JavaScript types, operators, objects, and methods

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use JavaScript types, operators, objects and methods". In daily operations, I believe that many people have doubts about how to use JavaScript types, operators, objects and methods. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use JavaScript types, operators, objects and methods". Next, please follow the editor to study!

JavaScript is an object-oriented dynamic language that includes types, operators, standard built-in (built-in) objects, and methods. Its syntax comes from Java and C, so many of the syntax features of these two languages are equally applicable to JavaScript. A major distinction to note is that JavaScript does not support classes, a concept that continues in JavaScript through object prototypes (object prototype). Another major distinction is that functions in JavaScript are also objects, and JavaScript allows functions to be passed like other objects while including executable code.

Number (digital)

String (string)

Boolean (Bull)

Symbol (symbol) (added to version 6)

Object (object)

Function (function)

Array (array)

Date (date)

Math (Mathematical object)

RegExp (regular expression)

Null (empty)

Undefined (undefined)

Error (question) type

1. Detailed explanation of number

Take full floating-point computing (double intensive reading 64-bit) in Javascript! We can also use the Math built-in object provided by JavaScript and the built-in function parseInt (). In addition, JavaScript also provides parseFloat (), but it only supports parsing decimal digits in parseInto ("123,10) / / eg:0.1-- > 10 means decimal.

ParseInt ("010", 10); / / 10

ParseInt ("010"); / / 8 if there is no second parameter, then 0 starts with octal 0x and starts with hexadecimal.

ParseInt ("0x10"); / / 16

How to convert binary to integer value?

ParseInt (10011, 2)

When the first parameter is not a numeric string parseInt ("hello", 10)

/ / NaNNaN is a special value and the result is NaN with any number.

In addition, there are two special values, Infinity and-Infinity (positive infinity and negative infinity). The built-in function isFinite () can be used 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. Each 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)

Null is essentially a null value and 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, an unassigned value. (JavaScript allows you to declare a variable without assigning a value to it. An unassigned variable is a undefined type)

Boolean type: (true / false) other types convert it

Flase, 0, ", NaN, null, undefined all implicitly convert to false when JavaScript needs a Boolean variable (the rest 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 +, -, *, /, and%-- congruence (unlike modular operations). Assignment uses the = operator, as well as some compound operators, such as + = and-=, which are equivalent to x = x op y.

+ can be used to connect strings

"3" + 4 + 5; / / 345

3 + 4 + "5"; / / 75

1 = true; / / false

123 = "123"; / / false

123123 / / true

1 = = true; / / true

6. Control structure

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

While ()

Do...while ()

For (;) / for (:)

Short circuit and: var name = o & & o.getName ()

Short circuit or: var name = otherName | | "default"

Ternary operator: var allowed = (age > 18)? "yes": "no"

Switch statements based on a number or string can be used for multiple branches: (expressions in switch and case are compared using the = = strict equality operator:)

Switch (action) {

Case 'draw':

DrawIt ()

Break

Case 'eat':

EatIt ()

Break

Default:

DoNothing ()

}

Switch (1 + 3) {

Case 2 + 2:

Yay ()

Break

Default:

Neverhappens ()

}

7. Object

How the object is created:

1.var obj = new Object ()

2.var obj = {}-> literal amount of object

Var obj = {

Name: "carrot"

"for": "Max"

Details: {

Color: "orange"

Size:12

}

}

You can use chained access:

Obj.details.color;//orange

You can access it with square brackets:

Obj [detail] [color]

Object type: (like a class in Java)

Function Person (name,age) {

This.name = name

This.age = age

}

Create an object for Person:

Var You=new Person ("zhangjiahui", "23")

You can use You.name= "ZJH"; to assign values

Var name=You.name; can be used to assign values

Obj ["name"] = "Simon"

At this point, the study of "how to use JavaScript types, operators, objects, and methods" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report