JS base 2js object, Operator date (), getHours ();

Source: Internet
Author: User

All things in JS are objects: strings, numbers, dates, and so on;

In JS, the object is the data that owns the property and method

Local JS variable

A variable declared inside a JavaScript function (using VAR) is a local variable, so it can only be accessed inside the function. (The scope of the variable is local).

You can use local variables with the same name in different functions, because only the function that declares the variable can recognize the variable.

The local variable is deleted as soon as the function is finished running

Global JS Variable

Variables declared outside of a function are global variables, and all scripts and functions on a Web page can access it.

The lifetime of the JS variable

The lifetime of JavaScript variables begins at the time they are declared.

Local variables are deleted after the function is run.

Global variables are deleted after the page is closed.

Assigning a value to an undeclared JS variable

If you assign a value to a variable that has not been declared, the variable is automatically declared as a global variable.

This statement:

Carname= "Volvo";

A global variable is declared carname, even if it executes within the function.

JS operator

comparison Operators

Comparison operators are used in logical statements to determine whether a variable or value is equal.

Given x=5, the following table explains the comparison operators:

operator Description Example
== Equals X==8 to False
=== Congruent (value and type) X===5 is true;x=== "5" is false
!= Not equal to X!=8 is True
> Greater than X>8 to False
< Less than X<8 is True
>= Greater than or equal to X>=8 to False
<= Less than or equal to X<=8 is True

logical operators

Logical operators are used to determine the logic between variables or values.

Given X=6 and y=3, the following table explains the logical operators:

operator Description Example
&& and (x < ten && y > 1) True
|| Or (x==5 | | y==5) is false
! Not ! (x==y) is true

Conditional operator (trinocular operator)

In JS, in addition to If. else and Swich statements, and a unique three-mesh operator? ... :

Grammar:

Conditions? STATEMENTA:STATEMENTB;

The above statement, first judge the condition condition, if the result is true to execute the statement Statementa, otherwise execute the statement statementb.

It is notable that the JavaScript script interpreter will be semicolon "; "As the Terminator of the statement, both the Statementa and the STATEMENTB statements must be single statements, and the use of multiple statements will give an error.

Example:

<!doctype html>

 Add an example of timing

<!doctype html>

  

JS base 2js object, Operator date (), getHours ();

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.