JavaScript for the front-end base

Source: Internet
Author: User
Tags arithmetic operators logical operators numeric value script tag

JavaScript Overview of JavaScript history
    • 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.
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.
how JavaScript is introducedwrite code inside the script tag
<script>  //write your JS code here </script>

  

Introduction of additional JS files
<script src= "Myscript.js" ></script>

  

JavaScript Language SpecificationComments (Comments are the mother of code)
This is a single-line comment/* This is a multiline comment */
Terminator

The statements in JavaScript are terminated with a semicolon (;).

JavaScript Language BasicsVariable Declaration
    1. The variable name of JavaScript can be composed of _, number, letter, $, and cannot begin with a number.
    2. declaring variables using var variable names; The format to declare
var name = "Beibei"; var age = 18;

  

Attention:

Variable names are case-sensitive.

Camel-named rules are recommended.

JavaScript data types

JavaScript has a dynamic type

var x;  At this point x is Undefinedvar x = 1;  At this point x is the number var x = "Beibei"  

  

Number Type

JavaScript does not differentiate between integral and floating-point types, there is only one numeric type.

var a = 12.34;var b = 20;var c = 123e5;  12300000var d = 123e-5;  0.00123

  

Common methods:

parseint ("123")  //Return 123parseInt ("ABC")  //Return Nan,nan property is a special value that represents a non-numeric value. This property is used to indicate that a value is not a number. Parsefloat ("123.456")  //Return 123.456

  

String

var a = "Hello" var b = "World;var c = a + B; Console.log (c);  Get HelloWorld

  

Common methods:

Method Description
Obj.length return length
Obj.trim () Remove whitespace
Obj.trimleft () Remove the left margin
Obj.trimright () Remove the blank on the right
Obj.charat (N) Returns the nth character
Obj.concat (value, ...) Stitching
Obj.indexof (substring, start) Sub-sequence position
Obj.substring (from, to) Get sub-sequences by index
Obj.slice (start, end) Slice
Obj.tolowercase () Lowercase
Obj.touppercase () Capital
Obj.split (delimiter, limit) Segmentation

Splicing strings generally use "+"

Boolean type

The difference between python,true and false is lowercase.

var a = True;var B = false;

  

Array

Similar to the list in Python.

var a = [123, "ABC"];console.log (A[1]);  Output "ABC"

  

  

Common methods:

Method Description
Obj.length The size of the array
Obj.push (Ele) Trailing append Element
Obj.pop () Gets the trailing element
Obj.unshift (Ele) Head Insert Element
Obj.shift () Removing elements from the head
Obj.slice () Slice
Obj.reverse () Reverse
Obj.join (seq) Concatenate array elements into a string
Obj.concat (Val, ...) Connection array
Obj.sort () Sort

To iterate over an element in an array:

var a = [Ten, A, 40];for (Var i=0;i<a.length;i++) {  console.log (i);}

  

  

Object

Similar to (in some respects) a dictionary data type in Python

var a = {"name": "Beibei", "Age": 18};console.log (A.name); Console.log (a["age"]);

  

  

Iterate through the contents of the object:

var a = {"name": "Alex", "Age": 18};for (var i in a) {  console.log (i, A[i]);}

  

  

null and undefined
    • Undefined means that when the declared variable is not initialized, the default value of the variable is undefined. There is also the undefined that is returned when the function has no definite return value.
    • Null indicates that the value does not exist

Undefined indicates that a variable was declared, but has not been assigned a value. Null declares the variable and the variable is a null value.

Type query
typeof "ABC"  //"string" typeof null  //"Object" typeof true  //"Boolean" typeof 123//"number"

  

  

typeof is a unary operator (like ++,--,! ,-the unary operator), is not a function, nor is it a statement.

Operator arithmetic operators
+ - * / % ++ --

comparison Operators
> >= < <= = = = = = = =!==

Attention:

1 = = "1"  //true1 = = = "1"  //False

logical Operators
&& | | !

Assignment Operators
= += -= *= /=
Process ControlIf-else
var a = 10;if (a > 5) {  Console.log ("Yes");} else {  Console.log ("No");}

  

If-else If-else
var a = 10;if (a > 5) {  Console.log ("a > 5");} else if (a < 5) {  Console.log ("A < 5");} else {  Console.log ("a = 5");}

  

Switch
var day = new Date (). GetDay (), switch (day) {case  0:  console.log ("Sunday");  break;  Case 1:  console.log ("Monday");  Break;default:  console.log ("...")}

  

For

JavaScript for the front-end base

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.