Web front-end basis (7): JavaScript (a)

1. JavaScript Overview

1.1 JavaScript Historical Background

• Brandon Archer (Brendan Eich, 1961 in ~), Netscape in 1995, the invention of JavaScript.

JavaScript is called a start LiveScript, but because the Java language was special fire, so in order to near the big, it was renamed JavaScript. As the relationship between "North" and "Beida Jade Bird" is. "Beida Jade Bird" is near "North" big.

There are other pages in the same period of languages ​​such as VBScript, JScript, etc., but were later defeated JavaScript, so now the browser, just run a scripting language is JavaScript.

1.2 What is JavaScript

JavaScript on the web is a powerful programming language for developing interactive web pages. It does not need to be compiled, but directly embedded in HTML pages and executed by the browser.

JavaScript was designed to add interactivity to HTML pages behavior.

JavaScript is a scripting language (scripting language is a lightweight programming language).

JavaScript by the number of lines executable computer code.

JavaScript is usually embedded directly into HTML pages.

JavaScript is an interpreted language (that is to say not precompiled code execution).

JavaScript is composed of:

Core (ECMAscript): grammar, sentence.

Document Object Model (DOM): document object model, operation of the document elements and content.

Browser Object Model (BOM): browser object.

1.3 JavaScript effects

Add a page using JavaScript animation, provide user experiences. The main applications are: embed dynamic text in an HTML page, the browser made for incident response, reads the HTML elements, verify submitted data, browser detection and other information visitors.

The introduction of the 1.4 JavaScript

The introduction of JavaScript in the HTML file, there are two ways, one is embedded in an HTML document directly JavaScript script, called embedded, the other is a link to an external JavaScript script file, called outreach style.

1. embedded in the HTML document, label is introduced by <script>, are as follows:

<html>
    <head>
        <script type="text/javascript">
            //此处为JavaScript代码
        </script>
        <title></title>
    </head>
    <body>
        
    </body>
</html>

2. outreach of formula, in an HTML document, the <script src = ""> tag introduced .js file as follows:

<html>
    <head>
        <script src="js/ad.js" type="text/javascript" charset="UTF-8"></script>
        <title></title>
    </head>
    <body>
        
    </body>
</html>

2. The basic syntax

2.1 Variable

1. When using JavaScript, you need to follow the following naming convention:

Must begin with a letter or an underscore, the middle can be numbers, characters, or underscores.

Variable names can not contain spaces and other symbols.

JavaScript can not use keywords as variable names, such as: function.

JavaScript strict case-sensitive.

2. declare variables

var variable name;   // JavaScript variables can not be declared directly. Default value: undefined

3. Assignment of variables

var variable name = value;   // the JavaScript variable is weakly typed, and the same variable may store different types of data

2.2 Data Types

Data types include: basic data types and the reference data type.

Refers to basic data types are simple segment data, reference data type means having a plurality of target values ​​thereof.

When we assign a variable to a variable, the parser is the first to confirm this value is a basic type value or a reference type value.

2.2.1 Basic Types

(1) number

var A = 123 ;
 // typeof check what type of data is variable current 
the console.log ( typeof A)
 // special case 
var A1 = 5/0; 
the console.log ( typeof E1) // Infinity infinite number type.

(2) string

var str  = '123'
console.log(typeof str)

(3) boolean

var b1 = false;
console.log(typeof b1)

(4) null

var C1 = null ; // . empty object Object 
the console.log (C1)

(5) undefined

var D1;
 // represents a variable is not defined 
the console.log ( typeof D1)

2.2.2 Reference types

Reference type is usually called a class (class), that is to say, encountered a reference value, the process is the object.

JavaScript is an object-based rather than object-oriented. The default value of the object type is null.

JavaScript provides a number of predefined reference type (built-in objects).

The article will explain later.

Operators 2.3

JavaScript python almost in line with the operation, we can look at my base in python operator python operators

Guess you like

Origin www.cnblogs.com/liuhui0308/p/11879151.html