0317-JS variable data type operator control statement

Source: Internet
Author: User
Tags string to number

key Memory ( routines ):
1. Key words: (must start with a letter, underscore (_), or dollar sign ($), identifier , variable (is a name, preferably preceded by a letter, is case-sensitive), constant (is a value with a data type)

  Variable:

① Define and assign values

② use
2. Data type: numeric string boolean null undefined object

   data type conversions:   Alert (typeof information); //Determine the data type of the information

Other type-to-string: Global method String () //string (123)

             Number, Boolean available tostring () //(ture). ToString

    String to number:parsefloat//Recommended Use

parseint (AA)//will take the whole

           Number (AA)//decimal operation will be problematic

3. Operators:

arithmetic operators:+-*/+ + (self-increase)-(self-subtract)% remainder

Self-increment and self-subtraction:

Only when you have a relationship with yourself, in front of no difference;

When participating in an expression: before //increment and re-operation in the back //first operation and then self-increment

assignment Operator:= + = = *=/=

+ =: A + = 2 ==> a = a+2;

relational operators:< > <= >=! = = = = = = = =

= =: Comparison value

= = = Comparison Value and type

Logical operators:

&&(with): Both sides are true, the result is true;

    || (OR) : as long as one side is true, the result is true;

! (non):! True=false;

 Ternary operators: //Handling simple (not true) judgments

An expression? Really do this: fake this;
4. Control statements

  for--code Example:

    var dy= "";      for (var i=1;i<10;i++) {        for (var j=1;j<=i;j++) {                dy =dy+j+ "*" +i+ "=" +i*j+ "&nbsp;&nbsp;" ;        }                Dy=dy+ "<br/>";        }    document.getElementById ("Dayin"). Innerhtml=dy;
For loop print multiplication table

if--code example:

// title: 50 kg below 0.13 yuan per kilogram, exceeding the portion per kilogram of 0.2 yuan // Assign the weight of the baggage entered to W var w = prompt ("Enter your baggage weight (KG)"),    y; // calculate freight According to the weight entered if (w <=) {    = w * 0.13;} Else {    // Primitive: 50*1.3+ (w-50) *0.2;    y = w * 0.2-3.5;} // The output Freight alert ("You need to pay the shipping cost is" +y+ "Yuan");
Shipping Issues

  switch--code Example:

Scissors Games: 0-Scissors 1-Fist 2-cloth//Assign the number you entered to youvaryou = prompt ("Please enter the 0/1/2 you want out of");//assign a computer's random number to a PCvarPC = parseint (Math.random () * 3);//alert ("Computer out of the number is" +pc);//judging the winning and losing according to the boxing situationSwitch(You) { Case"0":        Switch(PC) { Case0: Alert ("A very close");  Break;  Case1: Alert ("You lost.");  Break;  Case2: Alert ("You won.");  Break; default:             Break; }         Break;  Case"1":        Switch(PC) { Case0: Alert ("You won.");  Break;  Case1: Alert ("A very close");  Break;  Case2: Alert ("You lost.");  Break; default:             Break; }         Break;  Case"2":        Switch(PC) { Case0: Alert ("You lost.");  Break;  Case1: Alert ("You won.");  Break;  Case2: Alert ("A very close");  Break; default:             Break; }         Break; default:         Break;}
Scissors Mini Games

Array
Method (function)

A class is a set of commonalities.
An object is an XX in the collection and can have its attributes.

0317-JS variable data type operator control statement

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.