Java script basic concepts, variables, constants

Source: Internet
Author: User

1 , JavaScript Concept

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

2. 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

3. Basic grammar

* 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:/* */

4. 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]

5. 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

Java script basic concepts, variables, constants

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.