C-like Syntax
If several Objected-Oriented programming languages learned,you will find that p-languages are the same thing from their skins,c++,java,c#.It's not serious,just part of feelings.But if you mastered one OO-language,It's easy to conquer javascript.
- Case-sensitivity:Every object of javascript is Case-sensitivity,it means thatFunction people()is different fromFunction People().
- Comments:the same with c,use /**/ or //.
- Statements terminal sign:semicolon.Although omitting this sign makes no mistakes,you'd better to always include one,It's some kind of conventions.And maybe It's required in the next version.
Data types
- simples: Undefined,Boolean,Null,String,Number.
- complex:Object.yeah,It's complex enough,you will find it.
Undefined:
var message; //this variable is declared but has a value of undefined
//make sure this variable does not declared
//var age
alert(message); //”undefined”
alert(age); //causes an error
In this two cases,maybe the browser(like Chrome) shows the same errors,but only the none-defined variable makes a mistake-interrupt.
Null:
var ba = Boolean(1);//ba = true
var ba = Boolean(0);//ba = false
var ba = Boolean("");//ba = false
var ba = Boolean("noemptystring");//ba = true
Every not-null object will be covered to true,and the opposite is false.
Number:
Number type is double-precision value.It is easy to get the range of Number type using the property Number.MAX_VALUE and Number.MIN_VALUE.There is a special value in Number called NaN which is short for Not a Number,this value is not equal to any value even itself:NaN==Nan returns false.
Just like Boolean(),the function Number() can translate every object to number type,principle of the conversion is some a little complex,I don't want to copy it here.Generally,parseInt() andparseFloat() are better choice.
String:
String type in Javascript is very like it in C#/JAVA.Once defined,the value of it will never change.
There are two ways to translate an object to string,the general way is using function toString(),most of datatypes in Javascript have this function except null and undefined.Another method is String( argument ),it returns the same value when the arguments is not null or undefined,if null or undefined passed in,then this function will return "null" and "undefined".
Object:
Object is the base of all objects in javascript.everything in javascript is object.