A function represents a value

When we look at functions from the same window JavaScript does, things become clearer.

Take for example this function:

 var whatsup = function (){
 return "The sky is up!";
};

JavaScript looks at the function call and it only sees the final product, or what is supposed to return.

Call it like this:

"Do you know what? " + whatsup();

And JavaScript will reply with this:

Do you know what? The sky is up!

So the function was just a placeholder for “The sky is up!”.

By placing the string “The sky is up!”  in a function, we saved it and we are now able to call it at will, since the function is just like a Lego puzzle piece: we can plug it anywhere we want, and it always delivers if we interface it properly.

… Will continue tomorrow, mañana, amanhã, 明天, demain, morgen, 明日kesho …|
(Thank goodness for Google Translate!)

Advertisements

Author: tarau

technical writer, web technologies

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s