JavaScript Primer Basics _javascript Tips

Source: Internet
Author: User
Tags arithmetic arithmetic operators logical operators

JavaScript basic syntax

1, operator

An operator is a sequence of symbols that completes an operation, and it has seven classes:

Assignment operators (=,+=,-=,*=,/=,%=,<<=,>>=,|=,&=), arithmetic operators (+,-, *,/,++,--,%), Comparison operators (>,<,<=,>=,==,== =,!=,!==), logical operators (| |,&&,!), conditional operations (?:), displacement operators (|,&,<<,>>,~,^), and string operators (+).

Many people may not know what "= = =".

Here, I explain to you, in JavaScript, "= = =" is congruent only "= = =" Both sides of the memory address is also equal to return true

and "= =" is only equal value will return true

For example: Null==undefined will return true, but null===undefined will return false!

2. Expression type

The combination of operators and operands, called expressions, is typically divided into four classes: assignment expressions, arithmetic expressions, Boolean expressions, and string expressions.

3, statements

A JavaScript program consists of several statements, which are instructions for writing a program.

JavaScript provides the complete BASIC programming Statements: Assignment statements, switch selection statements, while loop statements, for loop statements, for Each loop statements, do-while loops, break-loop abort statements, Continue loop interrupt statement, with statement, Try...catch statement, if statement (if ...). Else,if...else If ... ), let statement.

4. function

A function is a named segment of a sentence that can be referenced and executed as a whole. Use functions to note the following points:

1 The function is defined by the keyword function (or by the function constructor);

2 functions defined using the Function keyword are within a scope that can be invoked at any place (including the statement that defines the function), and the definition of the VAR keyword must be defined before being invoked;

3 The function name is the name that is referenced when calling the function, it is sensitive to case, and cannot write the wrong function name when calling functions;

4 The parameter represents the value passed to the function or operation, which can be a constant, or a variable, or a function, which can be accessed by arguments objects within the function (the arguments object is a pseudo array, and the property callee refers to the called function).

5 The Return statement returns the value of an expression.

6 The yield statement throws an expression, and the interrupt function executes until the next call to next.

5. Object

An important function of JavaScript is the object-oriented function, which can be developed in a more intuitive, modular and reusable way through object-based programming.

6. Events

An action that occurs when a user interacts with a Web page, called an event. Events can be triggered by the user, or changes to the page, and even events that you can't see (such as the interactive progress of Ajax).

Most of the things are triggered by the user's action, such as: the user presses the mouse button, produced click event, if the mouse pointer to move on the link, resulting in mouseover events and so on.

In JavaScript, events are often used in support of event handlers.

7, variable

such as var myvariable = "some value";

The variable has its type, and the myvariable type is string (string) in the example above

Common types of JavaScript support are:

Object: Objects

Array: Arrays

Number: Numbers;

Boolean: Boolean value, only true and false two values, is the least memory in all types;

NULL: A null value with a unique value of NULL;

Undefined: No variables defined and assigned

Actually the JavaScript variable is a weak variable type, and you assign it to him as a string. It's numbers, he's plastic.

Is true and false he is a Boolean (note that you cannot add quotes, or you will be treated as a string).

The above describes the JavaScript basic syntax for the basics of JavaScript, and I hope it helps.

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.