Chapter III Basic Concepts (Part III: Operators)

Source: Internet
Author: User
Tags bitwise

Four. Operators 

Operators include arithmetic, bitwise operator relationship operators, and equality operators. The bitwise operator does not look at the moment.

  1. Arithmetic operations

Subtraction arithmetic. It's the same as the math book.

% modulo: Essentially, the trigger remainder is taken.

such as: 12%5 result is 2. Can be used to judge odd even numbers.

The "Case 1" table is a gray line of white. The HTML schema is as follows:

    <ulID= "UL1">        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>    </ul>

JS section:

    window.onload=function  () {        var oul=document.getelementbyid (' ul1 ');         var ali=oul.getelementsbytagname (' li ');          for (var i = 0; i < ali.length; i++) {            if(i%2==0) {// take even                ali[i].style.background= ' #f5f5f5 ';}}        ;    }

Even behavior Gray.

"Case two" time conversion rendering

In JS, n seconds =n/60 minutes +n%60 seconds

var n=1989; alert (parseint (n/60) + ' min ' +n%60+ ' s ')

Output to

  2. Increment and decrement operators

var age=29;

++age;

Equivalent to age=age+1. The predecessor decrement (--age) is similar to this. The predecessor Operation Mr. Foo calculates the second sentence, and then brings it into the first sentence. The post operator instead.

  3. Relationship Comparison

(1) <, >, <=, >= and mathematical definitions are exactly the same. The result of the operation returns a Boolean value.

(2) Equality (= =) will typically convert two data to a similar data type before comparing (implicit conversion), such as 55== "55". Again, for example, Null==undefined returns the true,null===undefined return is false, because the data types are different.

(3) = = = Congruent: more stringent equivalence. 55! = = = "55"

! = Implicit conversion type after comparison

!== Direct comparison without conversion

Note: = is an assignment operator, not a comparer.

  4. Boolean operators

Logical NON (!)

Take the inverse, contact the Boolean () function, the following judgments are established.

Object False
Empty string True
String False
0 True
Number False
Null True
NaN True
Undefined True

&&: Must be set up at the same time. Is true.

|| Or: Multiple conditions one of the conditions is true.

! No: Take the reverse. The alert (!true) result is false.

parentheses represent precedence operations.

  5. Assignment operators

is actually a shorthand for various assignments. The main purpose is to simplify assignment operations, and use them without any performance gains.

= Simple assignment.

+=:i+=2 means i=i+2.

The above two are used more.

-=:i-=2 means i=i-2.

*=,/=, and%= are similar.

  6. Comma

A comma is a separator that is used to complete multiple operations on a single line.

Chapter III Basic Concepts (Part III: Operators)

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.