The JavaScript basics of Python

Source: Internet
Author: User

Introduction to JavaScript

1. What is JavaScript?

is an object-and event-driven language that is applied to the client

    • Object-based: JS provides some objects, directly using
    • Event-driven: transform a picture every time you swipe your mouse
    • Client: refers to a browser

2, the characteristics of 2.JavaScript

    • Interactivity
    • Security: JavaScript cannot access the local hard disk
    • Cross-platform: JavaScript cross-platform, as long as the system is installed in a JavaScript-enabled browser, you can run JavaScript

3. JavaScript is made up of 3 parts

    • ECMAScript: Formulated by ECMAScript organization, syntax
    • Bom:broswer Object Model: Browser objects Models
    • Dom:document Object Model: Document objects Models
How to Write

1. JavaScript exists form

1<!--import JavaScript script Method--2<script type="Text/javascript"Src="js file"></script>3 4<!--writing javascript--> directly inside the HTML5<script type="Text/javascript">6 function func () {7Alert"111")8}

2, JavaScript code storage location

The body code block at the bottom of the HTML. Because the HTML code is executed from top to bottom, if the JS code in the head is time consuming, it will cause the user to be unable to see the page for a long time, if it is placed at the bottom of the body code block, even if the JS code is time consuming, it will not affect the user to see the page effect.

<! DOCTYPE html>

3. Declaration of variables and functions

Local variables in JavaScript must start with a Var, and if Var is not used, the default representation is to declare a global variable.

Function F1 () {            alert ("111")            var name = ' 222 ';//var variable name, preceded by variable name and var as local variable age            = ' 333 ';//global variable        }

Basic functions

The functions in JavaScript can basically be divided into three categories:

normal function    func (ARG) {        return true;    }          anonymous function    var func = function (arg) {        return "Tony";    }  Self-executing functions    (function (ARG) {        console.log (ARG);    }) (' 123 ')

Note: For function parameters in JavaScript, the number of actual arguments may be less than the number of formal parameters, and all actual parameters are encapsulated in the special value arguments within the function.

Scope

Each function in JavaScript has its own scope, and when a function is nested, a scope chain appears. When the inner-layer function uses a variable, it is based on the scope chain from the inner to the outer layer of the loop, and if it does not exist, the exception.

Remember that all scopes exist when the function is created and not executed.

function F2 () {    var arg= 111;    Function F3 () {        console.log (ARG);    }         return f3;} ret = F2 (); ret ();
数据类型

1. Digital

var a = 1;var B = 1.1;

2. Boolean type

Boolean (logic) can have only two values: TRUE or FALSE.  var x=truevar y=false

3. Arrays

Arrays in JavaScript are similar to lists in Python

Insert

Obj.unshift (ele)    Header Insert Element Obj.push (ele)       trailing append element obj.splice (n,0,val) specify position insert element

Removed from

Obj.shift ()         head remove Element obj.pop ()           tail Gets an element Obj.splice (n,1) specifies the     position of the delete element

Slice, invert, format

Obj.slice ()        slice obj.reverse ()      invert obj.join (Sep)       joins the array elements to construct a string

4. Dictionaries

A dictionary is a special form of an array

Dict = {' K1 ': 123, ' K2 ': 234} #定义一个字典Object {k1:123, k2:234}dict[' K1 ']123

The JavaScript basics of Python

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.