JavaScript Basics 2

Source: Internet
Author: User

First, the Math object

Math object: JS provides some of the math-related use methods

Math.ceil () rounding up

Math.floor () down rounding

Math.Round () rounding

Math.random () generates a random number from 0 to 1, which can be equal to 0 and not equal to 1

0 <= Math.random () < 1

Math.max (x, y) Gets the maximum value in x and y

Math.min (x, y) Gets the minimum value between x and y

Math.pow (x, y) Gets the Y-power of X (the Y-square)

Ii. Judging the type of data

Use the typeof provided by JS to get the data type of the variable

1 typeof (variable)

2 typeof variables

Iii. Conversion of data types

Convert numbers to Strings

1 number + " implicit conversion--" JS yourself convert data types

2 String (number) display Transform--"We did it ourselves."

3 number. toString ()

Convert a string to a number

1 + string with numeric content

2 Number (string with numeric content)

3 parseint () converted to integers

Convert parsefloat () to decimal

Convert to Boolean type

True False

1 !! Data -Implicit conversions

2 Boolean (data) display conversion

Iv. If...else

Syntax structure:

if (conditional expression) {

Code to execute when a conditional expression is set

} else {

Code that executes when a conditional expression is not valid

}

Five, logical operators

Function: Connect multiple conditional expressions

and && : requires multiple expressions to be set up at the same time

or | | : requires an arbitrary expression to be established

Non -! : Take counter

Six or three-tuple operator

Syntax structure:

Conditional expression? Data returned when an expression is formed: data returned by an expression that is not immediately

Seven, the Judgment Operator (ii)

= = Broad equals, compares the contents of two data

= = = Strictly equals, the comparison is content and type

VIII. special types in data types

Null represents an empty complex Type (object)

Undefined not defined

In JS, null,undefined,0, "", False,nan all mean false

Exercises:

JavaScript Basics 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.