Forget Java to learn Javascript from 0.--Day 1

The first day,when I read 'we need practice so we need a Javascript Interpreter.','Every browser has Javascript Interpreter.'

we can find them in the SETTING or TOOLS-> Developement Tools/Web console or just right click the page INSPECT ELEMENT.

so we don't need to install ANYTHING unless the browser,I know Chorme even IE 9 is fine,but Firefox is better.

 

Firstly , this book recommend a powerful tool called "Firebug",since I already bought this book,I would like to buy this tool and it's FREE!(Yay!)

the link to download Firebug is http://getfirebug.com/downloads (ONLY for Firefox,however FF is a better browser.I don't want to explain it now,we will see).

 

Secondly,I learnt the console.log() alert() to get some output.(seems like System.out.println() )

and then,I learnt "var" var for variable.

 

var x;      //define a var
x = 0;     //var can be number
x = 0.1;  //var can be float in JAVA,however it's Javascript
x = "hello world" //var can be string
x = 'Javascript'    //single quote is same,save our SHIFT,use single quote
x = true            //var can be boolean
x = null            //I feel var can be everything!!!
x = undefined     //very similar to null

"var" is like a baby,it's nothing,but it can be anything if you want.

 

most important part in Javascript is Object.

Object is name,value pair.

var book = {
topic : "Javascript",   
    
//the topic is like a field in Java
//"Javascript" is its value.
     
fat:     "true"
};

//and we can get the value of the "field" this way
book.topic // => it will be "Javascript"
book["fat"]//another way
//It's so simple and plain,let's learn something CRAZY!!!Yay!

it looks like just another way to write Java,right?Just don't use a specific type like int,float,string.

Is it that way?Come on!We will see.

book.author = 'Flanagan';    

//give it a new field and value after it already build

book.contents = {}

//give it a new object which is currently empty

NEVER know something like this before in Java right?

'Reflection' ? Yes,but this way is much more cleaner and beautiful,right?

I feel I start to like this little cute staff now.

posted on 2013-09-23 12:57  褐鹤  阅读(279)  评论(0编辑  收藏  举报

导航