JS data Types and methods

Source: Internet
Author: User
Tags logical operators mathematical functions

Data types and method data types
    1. Number does not distinguish between integers and floating-point numbers
    2. String strings
    3. Boolean True/false Boolean
    4. Object NULL Array
    5. function functions
    6. Undefined not defined

      Number method
      Method DES
      Number () constructor, parameters must be all numbers, otherwise Nan (not a number) is returned
      parseint () Converts a parameter to a number, and the integer part encounters a stop that is not a number
      Parsefloat () The argument is converted to a number, and a stop is encountered.
      ToFixed () Keep decimals (rounded), return string
      Note: The Nan data itself is not equal and the type is number
var str = "101.123px";var n = Number(str);alert(isNaN(N));//truealert( n == n );//false
Math Mathematical Functions
Method DES
Math.pow () Seeking the second party
Math.Round () Rounding to integers
Math.ceil () Rounding up
Math.floor () Rounding down
Math.min () Take the minimum value
Math.max () Take maximum value
Math.random () *n Random number of 0-n to be taken
var n = Math.random()*10 + 20//取10到30之间随机数parseInt(n)取整
String method
Method DES
Str[index] Take a single character ———— compatible ie8+
Str.charat (Index) Take a single character ———— compatible with all *
Number.tostring () Convert numbers to Strings
Str.touppercase () Capitalize a string letter
Str.tolowercase () Change the string letter to lowercase
Str.indexof ("Want to find text", the starting position of the query)
Str.substring () Intercept the string (the parameter will be compared between, which parameter is placed in the front, the parameter is negative, becomes 0)
Str.slice () Intercept string (parameter two cannot be less than parameter one)
Str.split ("Want to use it as a segmented text") Returns an array
Boolean Boolean value

Judging condition is true or False (true:1/flase:0)
Five false statements are as follows, and the rest are true, including empty objects, empty arrays

undefinednull0NaN""

Note: null and undefined

null转换为数字的时候 为0,在做条件判断为假   类似于正确空值的填补  undefined 转换为数字 为NaN,在做条件判断为假   类似于错误空值的填补null 关键字, 非对象undefined ==> undefined1+undefined ==> NaN1+null      ==> 1
JS operator Sign
DES
Operator + - * / %
Assignment operations = += -= /= %=
Judging condition symbols > < = = <= >=! = is not equal to!== = = = = Constant Equals, also determines the data type
logical operators With && or || not!

Can be calculated when the calculation will be performed, can not be calculated will be a variety of problems (error NaN);

    1. Except for the plus sign-*/% forces parameters to be converted to numbers
    2. Addition operations as long as there is a string, the addition is a string concatenation
    3. && conditions to stop and return to Flase
    4. || Condition encountered true stop, return True
For loop
for(var i=0; i<10; i++){            if( i==5 ){    //continue;跳过本次循环,到循环尾      break;//中断循环            }     console.log(i);}for(var key in document) {        console.log(key +"======"+document[key]); // 查看document里面所有的方法    }

Process Control

if ( 10>1 ) {        alert(1);    }else if( 5<50 ){        alert(2);    }else if( 10>20 ){        alert(3);    }    // 只有一条真语句    if( 8 > 0 ) alert(‘This is 8 > 0‘);

JS data Types and methods

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.