JavaScript learning Summary (1) Basic Part

Source: Internet
Author: User
Tags type null
Javascript is an interpreted language, and the browser acts as an interpreter. During js execution, it is explained before execution in the same scope. During the interpretation, the variables defined by function and var are compiled. After compilation, the variables are executed from top to bottom and assigned values.

Basic Concepts

Javascript is an interpreted language, and the browser acts as an interpreter. During js execution, it is explained before execution in the same scope. During the interpretation, the variables defined by function and var are compiled. After compilation, the variables are executed from top to bottom and assigned values.

Case Sensitive

All variables, function names, and operators in ECMASCript are case sensitive.

1. Variables

The variable is set to memory when it is used for the first time, so that it can be referenced in the script later. Declare variables before using them. You can use the var keyword to declare variables.

Var count, amount, level; // multiple declarations declared with a single var keyword.

Variable name

Variable names include global variables, local variables, class variables, and function parameters.

Variable names are composed of prefix types and meaningful words. The camper naming method is used to increase the readability of variables and functions. For example, sUserName and nCount.

Prefix specification:
Each local variable must have a type prefix, which can be divided:

S: string. For example, sName, sHtml; n: indicates a number. For example: nPage, nTotal; B: Indicates logic. For example, bChecked, bHasLogin; a: indicates an array. For example, aList, aGroup; r: indicates a regular expression. For example, rDomain, rEmail; f: indicates a function. For example, fGetHtml, fInit; o: indicates other objects not involved, such as oButton, oDate; g: indicates global variables, such as gUserName and gLoginTime;

JScript is a case-sensitive language. Follow the following rules to create valid variable names:

Note that the first character cannot be a number. It can be followed by any letter, number, or underline, but it cannot be a space variable name or a reserved word.

Javascript is a weak language that ignores unnecessary spaces. You can add spaces to the script to improve readability.

Var is a reserved word in javascript, indicating that the variable name is a user-defined identifier, and variables are separated by commas.

If a variable is declared but not assigned a value, the variable exists and its value is Jscript value undefined.

Forced type conversion

In Jscript, operations can be performed on different types of values without worrying about exceptions in the JScript interpreter. Instead, the JScript interpreter automatically changes (forced conversion) One of the data types to another, and then executes the operation. For example:

The calculation result value is added together with the string to forcibly convert the value to a string. Adding a Boolean value to a string forcibly converts a Boolean value to a string. Adding a value to a Boolean value forcibly converts a Boolean value to a value.

To explicitly convert a string to an integer, use the parseInt method. To explicitly convert a string to a number, use the parseFloat method.

JavaScript variable Survival: After you declare a variable in the function, you can only access the variable in the function. After exiting the function, the variable is revoked. This type of variable is called a local variable. You can use local variables with the same name in different functions, because only the declared functions can recognize each of these variables.
If you declare a variable outside the function, all functions on the page can access the variable. The lifetime of these variables starts after they are declared and ends when the page is closed.

Js variable Mind Map

2. js Data Type

Jscript has three types: main data types, composite data types, and special data types.

Main (basic) Data Types

Boolean string value

Composite (reference) Data Type

Composite (reference) Data Type

Object
Array

Special Data Types

Null

'Undefined'

String data type: the string data type is used to represent the text in JScript. In JavaScript, although double quotation marks ("") and single quotation marks ('') can represent strings, there is almost no difference between them. However, only double quotation marks ("") are used to indicate that the string is considered optimal.

A string value is a string of zero or more Unicode characters (letters, numbers, and punctuation marks ).

What is Unicode?

Unicode provides a unique value for each character, no matter what platform, program, or language. Unicode is developed to provide unified encoding for all characters in the world.

Numeric data type

We need to understand that JScript internally expresses all the values as floating point values, so there is no difference between integer and floating point values in Jscript.

Boolean data type

Boolean (logical) can have only two values: true or false.

Js array and Object

For more information, see my article-> javascript learning Summary--array and object Section

Null data type: You can assign a null value to a variable to clear the content of the variable.

In Jscript, the typeof operator reports the null value as the Object type, rather than the type null.

    
   
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.