JavaScript(1) 简介


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

No matter  which P-Language you beginning with,the data types must in the begginning chapter.So many beginnings make me confused,I cannot remembered  the exact size of int-datatype of different language.Okey,I am a lazy stupid.But if you are some kind of me ,you will like javascript for its simple datatype.Javascript only has six datatypes,five simple ones and a complex one.
  • simples: Undefined,Boolean,Null,String,Number.
  • complex:Object.yeah,It's complex enough,you will find it.

Undefined:

when defined a variable without initializing it ,this variable gets the default value "Undefined".It's important to remember that the variable is already defined,using a variable  not defined  will cause an error. eg in book:
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:

Null means an empty object pointer.Generally,variable defined but has no exact value  to give(you don't want to give a exact value ,because it may cause confuse.),you can initialize it with a Null value,it's better than not initialize.

Boolean
Boolean has two values:true and false.Attention, they are case-sensitive.It's funny that every type of value can be covered to Boolean by Boolean() Function.
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.

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值