JavaScript Learning notes--1. Basic knowledge

Source: Internet
Author: User
Tags bitwise operators logical operators

1. Using JS in HTML

<Script> Dosomething</Script><Scriptsrc= "Test.js"></Script><ahref= "Javascript:do Something">Link</a><Buttononclick= "Do Something">Button</Button>

PS: Multiple JS fragments or JS files in an HTML file are interlinked

2. Output

Alert (' Hello World ')    // box output document.write (' Hello World ')/    /  In-document output console.log (' Hello World ')    //console panel output

3. Syntax

Naming conventions:

Naming to make sense

Cannot start with a number

Cannot use System keywords, reserved words

Case:

Case sensitive

Variable name and function name using hump naming (AAABBBCCC)

Object name uppercase per first letter (object)

Use of semicolons:

var true;    // function execution statement, plus semicolon if (a) {  console.log (' Hello world! ') );  }     // struct definition statements, without semicolons

Comments:

Single-line Comment

/* * * Multi-line Comment

4. Variables

var variable name = variable value;

5. Data type

typeof ()//can be used for output variable types

Types include:

Number//digit, including integer and floating point (when processed or differentiated), because the floating-point number is approximate, do not use = = when judging

string//character; use + sign for connection, escape using \

// Example:  var a = ' world '; Console.log (' \ ' Hello ' + A + '!\ '); // ' Hello world! '

Boolean//Boolean;

object//objects; array and null are also part of this class, but they are still distinguished when processed

function//functions;

Undefined//undefined;

6. Operators

Arithmetic operator +-*/% + +--

Assignment operator = + = = *=/=%=

Conditional operators > < = = = >= <= = = =!==

Logical Operators && | | ! ^

Bitwise operators >> >>> << | & ~

Ternary operator? :

7. Process Control

Sequential structure

Branching structure

if(BOOL) {...}//Single channel
if(BOOL) {...}Else{...}//Two-way
if(bool) {...}Else if(bool) {...}Else { ... } //multi-channel for range matching
Switch(var) { Casevalue1: ... Break; Casevalue2: ... Break; default: ... } //multi-path for single value matching

Loop structure

 while(BOOL)//to judge the execution first, belong to the conditional type//Example:vari = 0; while(I < 100) {Console.log (‘#‘); I++; } Do- while()//perform the re-judgment first . for()//side judgment side Execution;//Example: for(vari=1;i<=9;i++){   for(varj=1;j<=9;j++) {Console.log (J+ "*" +i+ "=" + (j*i)); } console.log ("------------------");} Break    //Exit LoopContinue    //exit this cycle

Error handling

Try {...} Catch (e) {...}    // attempt and error handling

@zhnoah
Source: http://www.cnblogs.com/zhnoah/
This article is owned by me and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original
The right to pursue legal liability.

JavaScript Learning notes--1. Basic knowledge

Related Article

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.