The Power of Javascript: Basic Concepts - Javascript Statements
(Page 3 of 6 )
As you know, a script is executed line by line downward exactly as we read English. Take a look at the following English sentences:
Bring a piece of paper.
Bring a pen.
Write "Hello Dear."
When we read these sentences, we write them downward, or if they are all in the same line we will begin with the first one, then the second one, then the third and so on. A sentence in English has meaning; say "Bring me a piece of paper" to your friend, for instance, and he will give you a piece of paper. The sentence is terminated by the full stop symbol (.).
The same rules apply to Javascript. The English sentences are called statements in Javascript, and they execute downward. A Javascript statement is terminated with a semicolon (;) (you don't have to put it in, but for now let's just say that it's a good practice to terminate each statement with it). A statement instructs the interpreter to do something, like this statement:
var x = 2 + 1;
This statement adds 2 and 1, then puts the result in a memory place called x. We will discuss all these concepts in detail so you don't have to worry about how you can create such statements. This is enough to know about Javascript statements for now.
A Fast Look at Variables
To be able to continue with our discussion about the concepts in this article we must take a fast look at variables. The script statements (instructions) have to work on data; this is what programming is all about. We need a way to store data in the memory and operate on it.
A variable is a block of memory that is used to store data. It is called a variable because the value that's stored inside it can be changed.
Say that we have a memory location called x and we stored the value 243 in it. After a few statements in the script the value of x (which is 243) has been changed by a statement to the value 10, and after another three statements it has been changed to the value 567, and so on. So a variable is a memory location that we use to store data that we will operate on. What I mean by operate on is that we can add or multiply the value by another value, and perform may other operations on the value that we will learn about in the series. To declare that your script needs a memory location to store some data, we need to understand two important basic concepts in Javascript: keywords and identifiers.
Next: Keywords >>
More JavaScript Articles
More By Michael Youssef