"15" JavaScript

Source: Internet
Author: User

Javascript

A programming language that is compiled and run by the browser

First, JS existence form
    • JS file
    • HTML in the current code block

Placement: The bottom of the body tag, first display page content, and then load JS effect, prevent loading JS effect time too long affect the page display.

Second, JS variable

Local variable: var a = 123;

Global variables: a = 123; *****

PS Application Method: Variables are first set to local variables, need to set the global variables separately

<script>
Define function F1 () { var i = 123; local variable i = 123; global variable } F1 (); Alert (i);</script>
Third, JS data type

Primitive Type: Number, String, Boolean

Object type: Array, dictionary

1. Numbers (number)

Transformation:

parseint (): Converts a value to a number, or Nan if unsuccessful

Parsefloat () Converts a value to a floating-point number, or Nan if unsuccessful

2. Strings (String)

Racing Lights

<! DOCTYPE html>

3. Boolean

= = equals, Comparison value

= = = equals, comparison type and value

! = does not equal

!== not equal to, comparison type and value

&& and

|| Or

4. Arrays

Obj.splice (Start, DeleteCount, value, ...) inserting, deleting, or replacing elements of an array

Obj.join (Sep)

Python

JavaScript:li.join "_"

Iv. Other

1.JSON serialization

    • Json.stringify (obj) serialization
    • Json.parse (str) anti-sequence China

2. Escaping

    • decodeURI () characters that are not escaped from the URL
    • decodeURIComponent () non-escaped characters in the URI component
    • encodeURI () escape character in Uri
    • encodeURIComponent () escapes the characters in the URI component
    • Escape () escapes the string
    • Unescape () to escape string decoding
    • Urierror is thrown by URL encoding and decoding methods
V. Statements and exceptions

1. Conditional statements

If

Switch

2. Looping statements

Mode one: For

var li = [11,22,33,44]; // The first type for  for (var i = 0; i < 4;i++) {    Console.log (i, Li[i]);}

Way two: for can handle dictionary

var li = [11,22,33,44//  second for, index, can handle dictionary for (var  in li) {     console.log (Item,li[item])}

Way three: While

3. Exception Handling

try{}

catch (e) {}

finally{}

Active Throw exception: throw new Error (' xxxxx ')

Python throws Exception: Raise Exception (XXXXX)

Vi. functions

1. Basic functions

Common functions

function func (ARG) {     return true;}

anonymous functions

Function (ARG) {     return ' Tony ';};

Self-executing functions

(function (ARG)) {     alert (arg);} (123)

# for Encapsulation

2.JavaScript Scopes

    • No block-level scopes in JavaScript
    • JavaScript takes function scope
    • The scope chain of JavaScript
    • JavaScript is created before the scope chain is executed

"15" JavaScript

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.