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