First entry JavaScript Knowledge point (i)

Source: Internet
Author: User
Tags arithmetic operators logical operators

JavaScript Introduction
    1. Embedded

    2. Script tags introduced, generally in the body end tag introduced <script type= ' text/jacascript ' src= ' js file address ' ></script>

Data Type

There are 5 primitive types in JavaScript

    • Numeric type (number)

    • String type (String)

    • Boolean value type (Boolean)

    • NULL represents NULL

    • Undefined not defined

naming rules for variables
    • The first character can be any Unicode uppercase and lowercase letters, as well as the dollar sign ($) and underscore (_).

    • The second character, followed by a character, can also be used as a number. Cannot use reserved word as variable name

javascript reserved words

abstractboolean break bytecase catch char class const continuedebugger default delete do doubleelse enum export extendsfalse final finally float for functiongotoif implements import in instanceof int interfacelongnative new nullpackage private protected public return short static Super switch synchronized this throw Throws transient true try typeof var void volatile while with

operator
    • Unary operators manipulate one number

    • Binary operator Operation two numbers

    • Ternary operator Operation three number

return value

Operation Result of operator operation

Increment + + decrement--a++

The increment operator, after the operand, takes the value of the operand plus 1 as the return value

++a

The increment operator, before the operand, takes the value of the operand plus 1 as the return value

+ one Yuan plus

Data that converts other types of data to numeric types at the same time

-one yuan minus

Take the opposite number

typeof

The return value is the name of the type of the operand

Arithmetic Operators

+ - * / % take the remainder

NaN =notanumber

logical Operators

Different types of values are converted to Boolean values

empty string = false All others are true this null refers to a string that does not contain a string that contains no spaces value 0 = false All others are true null = false NaN = false undefined = false 1. Logic is not!

operator in front of the operand, the Boolean value of the operand is first evaluated, and the Boolean value opposite the Boolean value is returned.

2. Logic and $$ two consecutive $

The first operand is evaluated with a Boolean value. If this value is true, the return value is the second operand; otherwise, the return value is the first number.

3. Logic or | | Two consecutive |

The first operand is evaluated with a Boolean value. If this value is true, the return value is the first operand; otherwise, the return value is the second number.

short-circuit Operation

In logic with $$ or logic or | | , the second operand is not evaluated if the first operand can determine the result of the return value.

Relational Operators

Less than ( < ), greater than ( > ), less than or equal ( <= ), greater than or equal to ( >= ) These relational operators are used to compare two values. The rules of comparison are the same as what we learned in math class. These operators will return a Boolean value.

Equality operators

Equality operator ( == ), inequality operator (), equality != operator ( === ), non-equality operator ( !== )

equality and inequality = First conversion type re-comparisoncongruent and non-congruent = = Compare without conversion typeconditional operator (Trinocular operation)

Operand 1? Operand 2: Operand 3 to 1 de boolean value: 1 is True then the return value is 2,1 to false and the return value is 3

code Comments

The part of the source code that is ignored by the JavaScript engine is called a comment, and its purpose is to interpret the code. JavaScript provides two types of annotations: one is single-line comments, the // Other is a multiline comment, and the other is placed in /* and */ between.

Single-line Comment
?
/*** Multi-line Comment ***/
Judgment StatementIf statement

Grammar:

if (expression 1) {

Expression 2;

} expression 3;

Description : Program Judge expression 1, set up an execution expression 2, do not set the execution expression 3

2. If...else ... Statement

Grammar:

if (expression 1) {

Expression 2;

} else {

Expression 3;

} expression 4;

Description : Program Judge expression 1, set up an execution expression 2, do not set the execution Expression 3, and then execute the expression 4

3. If...else If ...

Grammar:

if (expression 1) {

Expression 2;

} else if (expression 3) {

Expression 4;

} else if (expression 5) {

Expression 6;

} else {

Expression 7;

} expression 8;

5. Switch Structure

var a = 1;

Switch (a) {

Case 1:
  Console.log (1);
    Break
Case 2:
  Console.log (2);
    Break
Case 3:
  Console.log (3);
    Break
Default:
  console.log ("Default");

}

Description : Jump out of the break: control statement; default: executes when all case does not match default ;

First entry JavaScript Knowledge point (i)

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.