The basic concept of learning notes in JavaScript advanced programming

Source: Internet
Author: User
Tags bitwise operators

System Learning JS,

Get started with JavaScript advanced programming, by learning jquery or angularjs source.

Chapter 1th Introduction to JavaScript

The purpose of the 1.JS is to handle some of the input validation actions that were previously responsible by the server-side language, such as Perl,
By Netscape-led development, then Microsoft's IE still can not dominate. Originally called LiveScript, the media stir Java, then renamed JavaScript.
JavaScript and ECMAScript usually refer to the same language, but JavaScript is the implementation and extension of the ECMA-262 standard. ECMAScript should be called a subset of JavaScript.


2. A complete JavaScript implementation should consist of the following three different parts:
Core (ECMAScript)
ECMAScript is a scripting language that is standardized by the ECMA International (formerly the European Association of Computer manufacturers) through ECMA-262.
Document Object Model (DOM)
is an API for XML-based application programming interfaces that are extensible for HTML. The DOM maps the entire page into a multi-tiered node structure.
Each component of an HTML or XML page is a node of a certain type, and these nodes contain different types of data.
The browser object model (BOM).
Developers use the BOM to control parts of the page that the browser displays. But the BOM does not have the relevant standard, until the HTML5 appears. HTML5 writes many BOM functions to the formal specification.

The 2nd chapter uses JavaScript in HTML

1. As long as you know the HTML page in the University class, you will not be unfamiliar with it.
The main way to insert JavaScript into an HTML page is to use the <Script> element. Use this element to mix scripts with tags, or to include external JavaScript files. Just open a Web page, look at the source code or F12, and you'll learn how to embed a JS script in the page.

It is important to note that the,<script> elements are parsed in the order in which they appear in the page. You can control the order of parsing using the defer and async properties. The Defer property allows the script to be executed after the document is fully rendered. The Async property indicates that the current script can execute asynchronously without waiting for other scripts or blocking document rendering.

However, the Async property applies only to external scripts (when using the SRC attribute), which is also a new property of HTML5.

The 2.<noscript> element can specify alternative content that is displayed in browsers that do not support scripting. However, if the page has script enabled.
The elements in the <noscript> tag will not appear as if they were commented out.

But now browsers that do not support scripting languages should not be able to find it?
Here is a section of the Web page code, concise and clear:

<body> ... <script type= "Text/javascript" ><!--document.write ("Hello world!" )//-</script><noscript>your Browser does not support javascript!</ Noscript></body>

Chapter 3rd Basic Concepts
This chapter introduces the basic syntax of JS. The syntax of JS is similar to the C language or other programming languages, simple to organize, focusing on the characteristics of JavaScript.

1.ECMAScript 5 introduces the concept of strict mode (strict modes). The strict mode defines a different parsing and executing model for JS.
Add code at the top: "Use strict".

2. For the ECMAScript keyword, the following describes the purpose of the relevant.
Break
Do
instanceof typeof and instanceof are often used to determine whether a variable is empty, or what type,

typeof Use the typeof operator for a value, you may return one of the following strings:
Undifined Boolean String Number Object
Function---if this value is functional.

Debugger
Default
Delete can remove a property of an object

Note that the following list of phrases may be in other languages, such as C, Java, etc. are keywords, but there is no real meaning in JS,
is also called a reserved word and cannot be used as an identifier. The reserved word can be conveniently extended after JS, and also can prevent the program from being misread.
Of course, different versions of ECMAScript differ in the limitations of reserved words.
Abstract
Boolean break byte
Case Catch Char class const continue
Debugger Default Delete do double
else enum Export extends
false Final finally float for function goto
if implements import in instanceof int interface
long native new null
Package Private protected public
return
Short static Super switch synchronized
This throw throws transient true try typeof
var void volatile
while with

3. Use the var operator when defining variables, such as: Var message;
This line of code defines a variable named message that can be used to hold any value that, before initialization, saves a special value,--undefined,
Of course, you can also initialize directly: var message = "HI";
and Java and other languages,JS variable also has scope, all variables defined using VAR will be defined in the scope of the variable local variables, if you omit Var,
You can create a global variable. However, this is not recommended. Like what:

function Test () {var message = "HI"; // Local Variables }test (); alert (message); // error, removing Var is correct,

4.ECMAScript has 5 simple data types: Undefined/null/boolean/number and string, another complex data type, Object,
object is essentially a set of unordered name-value pairs.
In particular, to understand the meaning of the undefined type, the function is to formally differentiate between object pointers and uninitialized variables.

Like undefined, a null type is also a data type with only one value, and a null value represents an empty object pointer, so the use of typeof to detect null values returns "Object".

var NULL ; alert (typeof//"Object"

If the defined variable is ready to be used to hold the object, it is better to initialize the variable to null so that the null value is checked to see if a reference to the object has been saved.

if NULL {// Execute action } Additionally, the value of undefined is derived from a null value, so: alert (null//True 

The 5.Boolean type has a function that is especially fun,

var msg = "Hello world! "; var msgasboolean=truefalse"""nullUndefined n /A undifined

These translation rules are applied in flow control statements, such as the IF statement.

var msg= "Hello world!" ; if (msg) {alert ("value is true!") );}

If you don't know the rules above, it's hard to understand the code.

6. Unlike other languages, ECMAScript does not define separate data types for integer and floating-point values, and the number type can be used to represent all values.
The number type handles different binary data,
var num1=070; Eight-binary 56
var num2=079; Invalid octal--79
var num3=08; Invalid octal--8

String type, double quotation mark, or single quotation mark can be represented,

The object type is the underlying type of all objects in ECMAScript.

7.JS statements are similar to other programming languages, such as
The for-in statement is used to iterate, for the property in expression, statement, as

 for (var in window) {document.write (proname);}

Use the Label statement to add tags to your code for future use:
Label:statement, such as

Start:for (var i=0;i<count;i++) {alert (i);}

The function of the WITH statement is to set the scope of the code to a specific object.
With (expression) statement

The 8.ECMAScript function does not have an attribute for function signatures. Without overloading, the same syntax appears in JS, and only the post-defined function is valid.

9.
The JavaScript language highlights a list of some of the non-recommended JS syntax, let's take a look.

1. = =JavaScript has two sets of equality operators, one set is= = and! =, the other group is = = = and!==. The former compares only the values of equality, while the latter compares the same types in addition to the values. Please try not to use the previous group, always use only= = = and!==. because = =type conversions are done by default and the rules are very difficult to remember. If you don't believe it, please answer the following five judgments whether the value is True or false:false= = ' false 'false==undefinedfalse==NULL    NULL==undefined0 = = "The first three are false, and the latter two are true. 2. withwith is intended to reduce keyboard input. Like Obj.a .=obj.b; OBJ.C=OBJ.D; can be shortened into with(obj) {a=b; C=D; However, when actually running, the interpreter will first determine if obj.b and OBJ.D exist, and if not, then determine if global variables B and D exist. This leads to inefficiencies and may cause surprises, so it is best not to use the WITH statement. 3The . Evaleval is used to execute a string directly. This statement is also not supposed to be used because it has performance and security issues and makes the code harder to read. Eval can do things without it. such as Eval ("myvalue = myObject." + MyKey + ";"); can be written directly myvalue=Myobject[mykey]; As for the JSON string returned by the Ajax operation, it can be run using the parser provided by the official website Json_parse.js. 4.ContinueThe function of this command is to return to the head of the loop, but the loop will return to the head. Therefore, the use of this command can be avoided by proper construction, resulting in improved efficiency. 5.SwitchThe case statements that run through the switch structure are executed sequentially by default, unless you encounter break,return and throw. Some programmers like to take advantage of this feature, such asSwitch(n) { Case1: Case2: Break; This is error-prone and difficult to find.  Therefore, it is recommended to avoid switch penetration, where there are case, all add break. Switch(n) { Case1: Break;  Case2: Break; }6. Single-line block structureif、 while, do, and for are block structure statements, but you can also accept single-line commands. Likeif(OK) T =true; even writeif(OK) t=trueThis is not good for reading code, and it is very error-prone to add statements in the future.  It is recommended that you add curly braces regardless of whether there is only one line of command. if(OK) {T=true; }7. + + and--increment operator+ + and decrement operators--, directly from the C language, can make the code very compact on the surface, but it actually makes the code look more complex and obscure. For the sake of the cleanliness and legibility of the code, therefore not for good. 8The . Bit operator JavaScript completely applies the bitwise operators of Java, including bitwise AND&, Bitwise OR |, bitwise XOR or ^, bitwise not ~, left shift <<, signed right shift >>, and right shift with 0 complement >>>. This set of operators is for integers, so it's completely useless for JavaScript, because all numbers inside JavaScript are saved as double-precision floating-point numbers. If you use them, JavaScript will have to convert the operands to integers before doing the arithmetic, which slows down the speed. andBitwise AND operator & Logical AND operator &&, it is easy to confuse. 9the. Function statement defines a function in JavaScript in two ways:functionfoo () {} andvarFoo =function() {} The two formulations are completely equivalent. However, when parsing, the previous method is automatically promoted to the head of the code, thus violating the function should be defined after the use of the requirements, it is recommended to define the function, all use the latter way of writing. 10The basic data type of the wrapper object for the basic data type of JavaScript includes strings, numbers, and Booleans, which have corresponding wrapper objects string, number, and Boolean. So, someone would define the relevant value:NewString ("Hello World"); NewNumber (2000); NewBoolean (falseThis writing is completely unnecessary and confusing, so it is not recommended. In addition,Newthe object and new array are also deprecated and can be replaced with {} and []. 11The . New Statement JavaScript is the first widely used language in the world to support lambda functions, essentially a functional programming language similar to Lisp. But the current world,80DThe programmers above are all using object-oriented programming. In order to get close to the mainstream, JavaScript has compromised, adopting the concept of classes, allowing objects to be generated from classes. The class is defined like this:varCat =function(name) { This. Name =name;  This. saying = ' Meow ' ; Then, regenerate into an objectvarMycat =NewCat (' Mimi 'This use of the function to generate classes, using new to generate the syntax of the object, in fact, is very strange, not intuitive. Moreover, when used, it is easy to forget to add new, it will become the execution function, and then inexplicably a few more global variables. Therefore, it is recommended that you do not create objects this way, but instead use a workaround. Douglas Crockford gives a function: Object.beget=function(o) {varF =function(o) {}; F.prototype=o; return NewF; The object is created using this function to manipulate the prototype object:varCat ={name:‘‘, saying:' Meow '}; varMycat =Object.beget (Cat); After the object is generated, you can assign a value to the related property: Mycat.name= ' Mimi ';12.voidin most languages, void is a type that represents no value.  In JavaScript, however, Void is an operator that accepts an operand and returns undefined. void0;//undefinedThis command is useless and confusing, and it is recommended to avoid it.

The basic concept of learning notes in JavaScript advanced programming

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.