Python Learning path Front end-javascript

Source: Internet
Author: User
Tags arithmetic operators constant math local time natural logarithm square root

Introduction to JavaScript

JavaScript is a literal-translation scripting language, which is a dynamic type, a weak type, a prototype-based language, and a built-in support type. Its interpreter, known as the JavaScript engine, is widely used as a scripting language for the client, and is used in HTML (an application under the standard Universal Markup Language) to add dynamic functionality to an HTML Web page.

Basic Features

JavaScript is a network scripting language, has been widely used in Web application development, often used to add a variety of dynamic features for Web pages, to provide users with more smooth and beautiful browsing effect. JavaScript scripts are typically embedded in HTML to implement their own functionality.
1. is an explanatory scripting language (the code is not precompiled).
2. It is used primarily to add interactive behavior to HTML (an app in standard Universal Markup Language) page.
3. You can embed HTML pages directly, but writing a separate JS file facilitates the separation of structure and behavior.
4. Cross-platform features, supported by most browsers, can be run on multiple platforms (e.g. Windows, Linux, Mac, Android, iOS, etc.).
The JavaScript scripting language, like other languages, has its own basic data types, expressions and arithmetic operators, and the Basic program framework of the program. JavaScript provides four basic data types and two special data types for working with data and text. The variable provides the place where the information is stored, the expression can complete the more complex processing.

Daily use

Embed dynamic text in HTML pages
Responding to browser events
Read and write HTML elements
Validating data before data is committed to the server
Detecting Visitor's browser information
Control of cookies, including creation and modification, etc.
Server-side programming based on node. JS Technology

Basic Features

(1) scripting language JavaScript is an interpreted scripting language, C, C + +, and other languages are compiled and executed, and JavaScript is interpreted line by row in the course of the program's operation.
(2) Object-based JavaScript is an object-based scripting language that can not only create objects, but also use existing objects.
(3) The simple JavaScript language uses the weak type variable type, does not make the strict request to the data type which uses, is based on the Java Basic statement and the control scripting language, its design is simple and compact.
(4) Dynamic JavaScript is an event-driven scripting language that does not require a Web server to respond to user input. When you visit a webpage, the mouse clicks or moves up and down the page, and the window moves, and so on, JavaScript can respond directly to these events.
(5) The cross-platform JavaScript scripting language is not dependent on the operating system and requires only browser support. So a JavaScript script can be used on any machine after it is written, provided the browser on the machine supports the JavaScript scripting language, and JavaScript is now supported by most browsers.
Unlike server-side scripting languages, such as PHP and Asp,javascript are primarily run as client scripting languages on the user's browser and do not require server support. So in the early days programmers preferred JavaScript to reduce the burden on the server, while at the same time brought another problem: security.
And as the servers are strong, programmers prefer to run scripts on the server to keep them safe, but JavaScript still has the advantage of being cross-platform and easy to use. At the same time, some special features (such as Ajax) must rely on JavaScript to support the client. With the development of engines such as V8 and frameworks such as node. JS, and its event-driven and asynchronous IO features, JavaScript is gradually being used to write server-side programs.

The form and location of JavaScript

The existence form of JavaScript

<! DOCTYPE html>

where JavaScript is stored

    • In the head of HTML
    • The bottom of the body code block of HTML (recommended)

Because the HTML code is executed from the top down, 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, but JS implementation is slow.

<script src= "https://www.gstatic.com/og/_/js/k=og.og2.en_US.iF4jnkQuaf0.O/rt=j/t=zcms/m=def/exm=in,fot/d=1/ Ed=1/rs=aa2yrtv5-poc4ks9gtgrdy2ywuwisqz7-q "></script><script>    alert (' 123 ');</script>
JavaScript variables

The declaration of a variable in JavaScript is a very error-prone point, the local variable must start with Var, and if Var is not used, the default is to declare a global variable.

<! DOCTYPE html>

Comments for code in javascript:

Single-line Comment://Multiline Comment:/*  */Description: This comment only takes effect in script
Data type

The data types in JavaScript are divided into primitive types and object types:

    • Original type
      • Digital
      • String
      • Boolean value
    • Object type
      • Array
      • Dictionary
      • ...

In particular, numbers, booleans, nulls, undefined, and strings are immutable.

Null is a keyword in the JavaScript language that represents a special value that is commonly used to describe "null values". Undefined is a special value that indicates that the variable is undefined

 

1. Numbers (number)

In JavaScript, integer values and floating-point values are not distinguished, and all numbers in JavaScript are represented by floating-point numbers.

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

Special values:

    • NaN, not a number. Can be judged using IsNaN (num).
    • Infinity, infinitely large. Can be judged using isfinite (num).

More numerical operations

Constant MATH.E constant E, base of natural logarithm. The natural logarithm of the math.ln1010. The natural logarithm of the math.ln22. math.log10e the logarithm of E with a base of 10. MATH.LOG2E the logarithm of E with a base of 2. MATH.PI constant Figs/u03c0.gif. The square of the math.sqrt1_22 is eradicated with 1. The square root of the math.sqrt22. The static function Math.Abs () calculates the absolute value. Math.acos () calculates the inverse cosine value. Math.asin () calculates the inverse chord value. Math.atan () calculates the inverse tangent value. Math.atan2 () calculates the angle from the x-axis to a point. Math.ceil () rounds a number. Math.Cos () calculates the cosine value. Math.exp () calculates the exponent of E. Math.floor () to a number of people. Math.log () calculates the natural logarithm. Math.max () returns the larger of the two numbers. Math.min () returns the smaller of the two numbers. Math.pow () calculates XY. Math.random () calculates a random number. Math.Round () is rounded to the nearest integer. Math.sin () calculates the sine value. MATH.SQRT () calculates the square root. Math.tan () calculates the tangent value.

2. Strings (String)

A string is an array of characters, but in JavaScript the string is immutable: You can access text anywhere in the string, but JavaScript does not provide a way to modify the contents of a known string.

Common features:

obj.length length Obj.trim () removes the blank obj.               Trimleft () obj.trimright) Obj.charat (n) returns the nth character in a string Obj.concat (value, ...)              Stitching Obj.indexof (Substring,start) sub-sequence position Obj.lastindexof (Substring,start) sub-sequence position obj.substring (from, to)                    Get sub-sequence Obj.slice (start, end) slice obj.tolowercase () uppercase Obj.touppercase () based on index                     Lowercase obj.split (delimiter, limit) split Obj.search (regexp) matches from the beginning, returning the first position where the match succeeded (G invalid) Obj.match (regexp) Global search, if there is a G in the regular means find all, otherwise only find the first one.                                     Obj.replace (regexp, replacement) replaced, there is g in the regular replaces all, otherwise only the first match, $ number: matches the nth group content;                                     $&: The content of the current match; $ ': text that is located to the left of the matched substring; $ ': Text on the right side of the matching substring $$: Direct amount $ symbol 

3. Boolean Type (Boolean)

The Boolean type contains only true and false, unlike Python, whose first letter is lowercase.

    • = = Compare Values equal
    • ! = does not equal
    • = = = Comparison value and type are equal
    • !=== Not equal to
    • || Or
    • && and

4. Arrays

Arrays in JavaScript are similar to lists in Python

Common features:

Obj.length          the size of the array Obj.push (ele)       tail Appends the element Obj.pop ()           tail Gets an element Obj.unshift (ele) The    head insert Element Obj.shift ()         Head remove Element Obj.splice (start, DeleteCount, Value, ...)  Inserts, deletes, or replaces elements of an array                    obj.splice (n,0,val) specifies the position of the insertion element                    Obj.splice (n,1,val) specifies the position of the replacement element                    Obj.splice (n,1)     Specify location Delete element Obj.slice ()        slice obj.reverse ()      invert obj.join (Sep)       joins the array elements to construct a string Obj.concat (Val,..)  Concatenate array obj.sort ()         to sort the elements of a group
Other

1. Serialization

    • Json.stringify (obj) serialization
    • Json.parse (str) deserialization

2. Escape

    • 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

3. Eval

Eval in JavaScript is a collection of eval and exec in Python that compiles code and can get return values.

    • Eval ()
    • Evalerror executing JavaScript code in a string

4. Regular expressions

Regular expressions are supported in JavaScript, which provides two main features:

    • Test (string) to detect if a regular match
    • EXEC (string) to get the contents of a regular match

Note: When you define a regular expression, "G", "I", "M" represent global matches, ignoring case and multiline matching.

5. Time Processing

Time-related operations are available in JavaScript, and time operations are divided into two types of time:

    • Time Unification Time
    • local time (East 8 district)

For more operations see: http://www.shouce.ren/api/javascript/main.html

Python Learning path Front end-javascript

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.