JavaScript Boolean (Boolean) object

Source: Internet
Author: User
Tags arithmetic

1.JavaScript Boolean (Boolean) object

A Boolean (Boolean) object is used to convert a non-Boolean value to a Boolean value (True or false).

1.1 Complete Boolean (Boolean) object reference manual

1.2 Creating a Boolean Object

A Boolean object represents two values: "True" or "false"

The following code defines a Boolean object named Myboolean:

var myboolean=New Boolean ();

If the Boolean object has no initial value or its value is:

    • 0
    • -0
    • Null
    • ""
    • False
    • Undefined
    • NaN

Then the value of the object is false. Otherwise, its value is true, even when the value of the variable is the string "false"!

2.JavaScript Math (Arithmetic) object

The Math object works by performing common arithmetic tasks.

2.1 Complete Reference manual for Math objects

2.2Math objects

The Math object works by performing normal arithmetic tasks.

The Math object provides a variety of arithmetic value types and functions. You do not need to define it before using this object.

var x=Math.PI; var y=math.sqrt (+);

2.3 Calculation value

JavaScript provides 8 arithmetic values that can be accessed by the Math object:

You can refer to the following JavaScript constants using this method:

Math.EMath.PIMath.SQRT2Math.SQRT1_2Math.LN2Math.LN10Math.LOG2EMath.LOG10E

2.4 Arithmetic methods

In addition to the arithmetic values that can be accessed by the Math object, there are several functions (methods) that can be used.

The following example rounds a number by using the round method of the Math object.

document.write (Math.Round (4.7));

The above code output is: 5

The following example uses the random () method of the Math object to return an arbitrary number between 0 and 1:

document.write (Math.random ());

The above code output is:

0.6671303459705329

The following example uses the floor () method and random () of the Math object to return a random number between 0 and 11:

document.write (Math.floor (Math.random ()));

The above code output is: 5

JavaScript Boolean (Boolean) object

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.