A brief introduction to the Javascript:js of the front

Source: Internet
Author: User
Tags arithmetic arithmetic operators logical operators object model alphanumeric characters

A brief introduction to JavaScript (JS)

First, The history of JavaScript

    • 1992 Nombas developed the embedded scripting language for C-minus-minus (c--) (originally bundled in Cenvi software). Rename it scriptease. (The language that the client executes)

    • Netscape (Netscape) received Nombas's philosophy, (Brendan Eich) developed a set of Netscape scripting languages in its Navigator livescript 2.0 product. Sun and Netscape are done together. And then the name is JavaScript.

    • Microsoft then emulated a JavaScript clone called JScript in its IE3.0 product.

    • To unify the three, the ECMA (European Computer Manufacturing Association) defines the ECMA-262 specification. The International Organization for Standardization (ISO/IEC) also adopted ECMAScript as the standard (iso/iec-16262). Since then, Web browsers have struggled (albeit with varying degrees of success and failure) to ECMAScript as the basis for JAVASCRIPT implementations. ECMAScript is the norm.

Second, ECMAScript

Although ECMAScript is an important standard, it is not the only part of JavaScript, and certainly not the only one that is standardized. In fact, a complete JavaScript implementation is made up of the following 3 different parts:

    • Core (ECMAScript)
    • Document Object Model (DOM) Documents object models (consolidated js,css,html)
    • Browser object models (BOM) Broswer object Model (integrated JS and browser)
    • The vast majority of Javascript in development is object-based. It is also object-oriented.

To put it simply, ECMAScript describes the following:

    • Grammar
    • Type
    • Statement
    • Key words
    • Reserved words
    • Operator
    • Object (encapsulates inherited polymorphism) object-based language. Use an object.

Third, JavaScript basics

1.How to introduce JS

1 Direct Write    <script>        alert (' Hello Yuan ')    </script>2 import file    <script src= "Hello.js" > </script>

Variables of 2.JS,

1. Declaring variables without declaring variable types, all using the var keyword

var a;<br>a=3;

2. a row can declare multiple variables. And can be of different types

var name= "Yuan", age=20, job= "lecturer";

3. a row can declare multiple variables. And can be of different types

4. variable name, the first character can only be letters, underscores, $ US dollar symbol Three select one, the remaining characters can be underscores, dollar signs or any alphanumeric characters and case-sensitive, x and X are two variables

The first letter of the Camel notation is lowercase, and the next letters begin with uppercase characters.  For example:var mytestvalue = 0, Mysecondvalue = "Hi" = 0, Mysecondvalue = "Hi" = 0, Smysecondvalue = "HI";

3. Constants and identifiers

Constants : Data values that appear directly in the program

Identifier:

    1. Consists of letters, numbers, underscores (_), Dollar signs ($) that do not begin with a number
    2. A name commonly used to denote functions, variables, etc.
    3. For example: _ABC, $ABC, abc,abc123 is an identifier, and 1ABC is not
    4. Words that represent a particular meaning in the JavaScript language are called reserved words and do not allow programs to be redefined as identifiers

Key words:

  

Data type of 4.JS

The data types are:

     Number-----  Numeric Boolean    -----  boolean string     -----  string undefined  -----  Undefinednull       -----   NULL  

Number type:

    • Integer and floating-point values are not distinguished;

String type (String):

is a sequence of Unicode characters, numbers, punctuation marks, string constants are enclosed in single or double quotation marks, and there are no character types in JavaScript, and expressions of common special characters in strings;
Some special characters in a string must be accompanied by a right dash \; Common escape character \ n: newline \ ': single quote \ ': double quote \ \: Right Dash

Boolean type (Bolean):

The Boolean type has only two values: True and False, also representing 1 and 0, in the actual operation True=1,false=0
Boolean values can also be considered on/off, yes/no, 1/0 correspondence True/false
The Boolean value is primarily used for JavaScript control statements, such as:

if (x==1) {      y=y+1;} else{      y=y-1;      }
Null and undefined types

Undefined type

The 1.Undefined type has only one value, which is Undefined. When the declared variable is not initialized, the default value of the variable is undefined.

2. When the function has no definite return value, the returned value is also "undefined";

Null type

Another type with only one value is null, and it has only one private value, NULL, which is its literal. The value undefined is actually derived from the value null, so ECMAScript defines them as equal.

Although the two values are equal, they have different meanings. Undefined is a value that is assigned to a variable when it is declared but not initialized, and null is used to represent an object that does not already exist (this is briefly described when discussing the typeof operator). If the function or method is to return an object, the object returned is usually null when it is not found.

Iv. operators

Operator classification

Arithmetic operator:    +   -    *    /     %       + +-        -comparison operator:    >   >=   < <= =    = = =    = = = = =   !== logical operator:     &&   | |   ! Assignment operator:    = = = =  *=   /= string operator:    +  join, either side operand has one or two is a string do join operation

Arithmetic operators: self-increment, self-decrement

++i: First calculated after assignment i++: first assigned value after calculation

If x=2, then the value of the X + + expression after the execution of the 3,x--expression is 1;i++ equivalent to i=i+1,i--equivalent to i=i-1;

JS differs from Python and is a weakly typed language

The ability to convert data is called weakly-typed Console.log (' 1 ' ==1)  //trueconsole.log (' 1 ' ===1)  //false  strongly typed print (1= ' 1 ')//false
strongly typed and weakly typed
1 Static type language2 a language that determines the data type during compilation. Most static type languages guarantee this by requiring that their data types be declared before any variables are used. Java and C are statically typed languages. 3 Dynamic Type language4 a language that determines the data type during runtime, as opposed to a static type. VBScript and Python are dynamic types because they determine that the type of a variable is the first time you assign it a value. 5 strongly typed languages6 a language that always enforces type definitions. Java and Python are mandatory type definitions. You have an integer that cannot be applied as a string if it is not explicitly converted. 7 Weakly typed languages8A type of language that can be ignored, as opposed to a strong type. JS is a weak type. In JS, you can concatenate the string ' 12 ' and the integer 3 to get the string ' 123 ', and then you can think of it as an integer 123, all of which do not require any display conversions. 9 so Python is both a dynamic type language (because it doesn't use a display data type declaration) and a strongly typed language (because it's actually the same type as long as a variable gets a data type). Ten  OneStrongly typed and weakly typed
strongly typed and weakly typed

Note 3: NaN

var d= "Yuan";    D=+d;    alert (d);//nan: A special value of type number, which gets a NaN data alert (typeof (D)) when it encounters an invalid to convert a string to a digit    ;//number    //nan features:        var N=nan;        alert (n>3);    alert (n<3);    alert (n==3);    alert (N==nan);        alert (N!=nan); All operations that//nan participate in are false, except! =
Comparison operators
>   >= < <= = = = =    = = =   !==

equals and non-equal operators are all equal and non-full equals. The two operators do the same as equals and non-equals, except that they do not perform type conversions until they are checked for equality.

  Console.log (2==2); True  console.log (2== ' 2 ');//true  because JS is a weak type, so it returns True  Console.log (2=== ' 2 ');//false (= = = The type is judged, The type is not the same as false)  Console.log (2!== ' 2 ');//true! = = and = = = is the opposite

Attention:

var bresult = "Blue" < "alpha"; alert (bresult); Output true in the above example, the string "Blue" is less than "alpha" because the character code for the letter B is 66, and the character code for the letter A is 97. Comparing numbers and strings another tricky situation occurs when you compare numbers in two strings, such as var bresult = "3", and alert (bresult); Output "True" above this code compares the string "25" and "3". Two operands are all strings, so the comparison is their character code ("2" character code is 50, "3" character code is 51). However, if one of the operands is a number, the result is interesting: var bresult = "< 3;alert" (Bresult); Output "false" here, the string "25" will be converted to the number 25, and then compared with the number 3, the results are expected. Summary: Comparison operators on both sides if one is a numeric type and one is a different type, its type is converted to a numeric type. If both sides of the comparison operator are of type string, the ASC code of the highest bit is compared, and if the highest bit is equal, continue to take the second bit comparison.

logical Operators

Console.log (1&&3); 3  two are true (0 is false, other figures are true) Console.log (0&&3);//0  as long as there is a false Console.log (0| | 3); 3  console.log (2| | 3); 2

V. Process Control

    • Sequential structure (executed from top to bottom)
    • Branching structure
    • Loop structure

Branching structure:

1. If.....else Structure:

if (expression 1) {    statement 1;} else if (expression 2) {    statement 2;} else if (expression 3) {    statement 3;} else{    statement 4;}

2.switch-case structure

Switch basic format switch (expression) {case    value 1: statement 1;break;    Case value 2: statement 2;break;    Case Value 3: statement 3;break;    Default: statement 4;}

Example

Switch (x) {case 1:y= "Monday";    Break;case 2:y= "Tuesday";    Break;case 3:y= "Wednesday";    Break;case 4:y= "Thursday";    Break;case 5:y= "Friday";    Break;case 6:y= "Saturday";    Break;case 7:y= "Sunday";    break;default:y= "undefined";}

Switch is more concise and clear than the else if structure, making the program more readable and more efficient.

Looping statements

For loop: (recommended)

Syntax rules: for    (initial expression; conditional expression; self-increment or decrement)    {            Execute statement ...    }

another form of a For loop:

For (variable in array or object)    {        Execute statement ...    }

While loop:

Syntax rules: while (condition) {    statement 1; ...    }

Vi. Exception Handling

try {    //This piece of code runs from top to bottom, where any one of the statements throws an exception the code block ends running}catch (e) {    ///If an exception is thrown in a try code block, the code in the catch code block is executed.    //e is a local variable that is used to point to an Error object or other thrown object}finally {//Whether or not the code in the     try is thrown (even if there is a return statement in the try code block), the finally code block is always executed. }

A brief introduction to the Javascript:js of the front

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.