Basic JavaScript knowledge

Source: Internet
Author: User

There are many types of JavaScript variables.

When you assign a text value to a variable, enclose the value in double or single quotation marks.

Do not use quotation marks when the value you assign to a variable is numeric. If you enclose a value in quotation marks, the value is treated as text.

JavaScript is sensitive to capitalization.

JavaScript does not use a value to declare a variable whose value is actually undefined.

After the following statement has been executed, the value of the variable carname will be undefined:

var carname;

If you re-declare a JavaScript variable, the value of the variable is not lost:

After the following two statements are executed, the value of the variable carname remains "Volvo":

var carname= "Volvo";
var carname;

JavaScript Boolean (logic) can have only two values: TRUE or FALSE.

The following code creates an array named cars:

var cars=new Array ();
Cars[0]= "Audi";
Cars[1]= "BMW";
Cars[2]= "Volvo";

or (condensed array):

var cars=new Array ("Audi", "BMW", "Volvo");

or (literal array):

var cars=["Audi", "BMW", "Volvo";

JavaScript objects

Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:

var person={firstname: "Bill", LastName: "Gates", id:5566};

The object (person) in the example above has three attributes: FirstName, LastName, and ID.

Object properties are addressed in two ways:

name=person.lastname;name=person["LastName"];

Undefined and Null

Undefined This value indicates that the variable does not contain a value.

You can empty a variable by setting the value of the variable to null.

Basic JavaScript knowledge

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.