JavaScript Learning Notes

Source: Internet
Author: User
Tags array length

1. JavaScript is case-sensitive,

Single-line Comment

/**/Multi-line comments

2. Variables:

var quantity; declaring variables

Quantity = 3; variable assignment

Variable names begin with a letter, dollar sign, underscore, and cannot begin with a number. And you cannot use keywords and reserved words as variable names, usually using the hump naming method, such as Firstnameword,

3. Data type:

Number, string, undefined, Boolean, null, Oblect,array, Date,math, RegEx string expression: "" ' double quote, single quote,

4, array:

var color = [' white ', ' black ', ' Yellow ']; This method of creation is called an array literal;varnew Array (' White ', ' Pink ' ); This is an array constructor;varnew  Array (); Array.push ()   ; Inserting data Array.item (0); Get array data;
ARRAY[0]; Gets the array data; The index value of the array starts from 0 to the array length -1

5, Operator:

NaN (not a number)

Assigned value =

Arithmetic operator: +-*/% + +--

String operator: +

Comparison operators: > < >= <=! = = = = = = =!==

6, Function:

//basic structure of a functionfunctionChange () {return' Hellowolrd ';}//function CallChange ();//functions with ParametersfunctionChange (width,height) {returnwidth*height;}//function calls with parametersChange (20,30);

Functions that return multiple values

function GetSize (width,height,dept) {
var size = Width*height;
var clome = width*height*dept;
var sizes = [size, clome];
return sizes;
}

GetSize (100,20,30) [0]; Gets the return value of one

anonymous functions

var change = function () {
Return ' helloworld! ‘;
}

var value = Change (); Call

Call function expression immediately
var area = (function () {
var width = 3;
var height = 4;
return width*height;
}());

7, Object

//object creation: The literal methodvarText ={name:' Zhangsan ', Age:15, Sex:true, GetName:function(){return  This. Name;};//Accessing ObjectsvarName =Text.name;varName =text.getname ();varname = text[' name '];//Create object: constructor Syntaxvarhotel =NewObject (); Hotel.name= ' quart '; hotel.address= ' Beijing '; Hotel.getroom=function(){return(a) ;//Modifying Objectshotel[' name '] = ' HaHa ';//Delete ObjectDeletehotel[' name '] Use keyword delete;//constructor SyntaxfunctionHotel (name,age) { This. Name =name; This. Age =Age ; This. Hostel =function(){returnRoon;};}//Usevarhotel =NewHotel (' Guyojiu ', 23);

Arrays are also objects

JavaScript Learning Notes

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.