JavaScript Basics (Concepts, constants, and variables)

Source: Internet
Author: User
Tags html tags object model

1 , JavaScript Concept

JavaScript is a scripting language; After writing, you can run it directly (the process of compiling is missing)

2 , JavaScript Development

LiveScript + JavaScript = Jscript = ECMAScript (standard for scripting languages)

||                   ||                 || ||

95 Netscape, Netscape United Sun, United Microsoft, tri-European Association of Computer Manufacturers, Inc.

Note: JavaScript syntax refers to the Java language; but "JavaScript is the scripting language of the Java language" is wrong

3 , JavaScript Component

ECMAScript: The standard of language (definition grammar) since the introduction of ES6 in 2015; A new version will be introduced every year in the future

Dom-document object Model (Document object models)

Bom-browser Object Model

4 , how to use JavaScript

Scripting JavaScript language with <script> elements:

(1) Define <script> elements, write directly

(2) through the <script> elements, the introduction of external JS file format: <script src= "js file path" ></script>

Type Property-Sets the currently introduced file types (text/javascript)

Note:<script> elements are written by default in

Even if it is written in an incorrect location: The browser does not have any errors, and the browser automatically resolves to change the error location to the correct location. (HTML is not a strict markup language)

5 , Test JavaScript Code

? Confirm (');

? alert ('); Rarely used at the moment (print content limited-not conforming to development requirements)

? prompt ('); Receive user information, the page has an input box to fill in the information

? document.write ('); The content of the test outputs the message directly on the page, and can be written with HTML tags.

? Console.log ('); Output messages in the console (console) in the browser's developer tool

Format: Console. Log(' log content '); Console. Warn(' output warning ');

Console. Info(' output information '); Console. Error(' output error ');

6 , basic syntax

* Case Sensitive Eg:atguigu, Atguigu and Atguigu-for three content

* Code of the normative

HTML: The element name is suggested using lowercase; Parent and child elements, recommended indentation (Space or TAB)

CSS: Combo selector #id,. class;

The specific wording of the CSS declaration eg: selector {

background-color:red;

}

* JavaScript: A line is best to write only one statement; It is recommended to write a semicolon after each statement;

Add a blank line between the two statements, and write a clear comment;

Keywords and reserved words cannot be used to define variable names;

Keywords: have special meanings in JavaScript code; Reserved words: Keywords that are not yet enabled

(Single-line comment) symbol://[shortcut: CTRL +?] (Multiline comment) symbol:/* */

7 , Variables

Concept: A container for storing data information. Format: var variable name = data content;

Features: Allows for repeated use of specific data functions: Allows the reuse of a specific data content

ü Declaration of variables

Duplicate declaration: A JavaScript variable can store only one data, and the previously stored data is overwritten.

Omission statement: Directly read the value of a non-declared variable, JavaScript will error.

Eg:console.log (test1); --Error because there is no definition test1

ü Naming rules

Start with a letter, underscore-, dollar sign $;   Does not begin with a number; Uppercase and lowercase letters do not conflict;

Do not use keywords and reserved words as names; names should have a clear meaning.

ü Usage

2 Defining variables-Define a variable name for a data

When there are multiple variables: (1) Each row defines a variable (2) Single row to define multiple variables, separated by commas

2 Call variable-use the data content of the variable

Define variables first, then call variables [normal]

When the browser loads the execution of the JavaScript code-from top to bottom, when a variable is called, the variable already exists

? Call the variable first, then define the variable---"Undefined"

Console.log (TEST2);    ==> var test2; --Define the variable (but not assigned value); The default value is "undefined"

var test2 = 300; Console.log (TEST2);

Test2 = 300; --Assigning values to variables

[Duplicate declaration: The corresponding data content will be overwritten with duplicate assignment: the corresponding data content will be overwritten]

8 , Constants

Format: const constant name = data content; Function: Represents a specific data content

Note: A variable that is read-only (cannot be modified), and the constant name is used in all capitals

* Constant declaration, must be initialized operation, otherwise it will report an error.

* Whether repeated or repeated assignment-constant will be an error

JavaScript Basics (Concepts, constants, and variables)

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.