JavaScript the next day

Source: Internet
Author: User

First, the data type

1. Strings (String)

var mood = "Happy";

var mood = ' happy ';

2. value (number)

var age = 25;

var price = 33.25;

3. Boolean Type (Boolean)

Boolean data can only have two values of true and false;

var married = true;

var married = false;

Unlike strings, do not enclose Boolean values in quotation marks. A Boolean value of false and the string "false" are two different things.

4. Objects (object)

Date Day Object

Date objects are used to process dates and times.

Code: var today = new Date ();

var year = Today.getfullyear ();

var month = Today.getmonth () + 1;

var day = Today.getday ();

5. array Arrays (object)

The index of an array is set to 0 by default.

Defining arrays

var arr = new Array (23,23,45,56,435);

var arr2 = [23,34,546];

var arr3 = new Array ();

Arr3[0] = 234;

ARR3[1] = 234;

Ii. viewing and conversion of data types

1. View data type typeof

var mood = "Happy";

Alert (typeof mood);

Alert (typeof 95);

2. Convert to String

var married = false;

Alert (married.tostring ()); Outputs "false"

var age = 25;

Alert (age.tostring ()); Outputs "25"

3. Convert to digital

Convert parseint () to integers

Parsefloat () converted to floating point number

Cases:

var test = parseint ("Blue"); Returns NaN

var test = parseint ("1234blue"); Returns 1234

var test = parseint ("22.5"); Returns 22

var test = parsefloat ("1234blue"); Returns 1234

var test = parsefloat ("22.5"); Returns 22.5

4. determine the type of variable

A, Judge the string

typeof (a) = = ' String '

B, judging the value

typeof (a) = = ' Number '

c If it is a numeric type, but the content is not a valid number, it will show Nan, judging nan

IsNaN (a)

D, determine if the variable is empty (no variable is defined.) or define a variable but not initialize it will appear)

typeof (a) = = ' undefined '

Third, operator

1. Arithmetic operators (+-*/%)

Add, subtract, multiply, divide, and balance, where% is the remainder operation

var total = (1 + 4) * 5;

var i = 100;

var temp = (i–20)/2;

Alert ("ten" +)//return 1020;

Alert (+)//return 30;

JavaScript the next day

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.