What’s in a statement?
“JavaScript is more than you might think,” a JavaScript statement, or expression,
is a collection of tokens of various categories including keywords, literals, separators, operators,
and identifiers that are put together to create something that makes sense to the JavaScript interpreter.
A statement usually ends with a semicolon, except in special cases like loop constructors such
as if, while, and for,”
Here are some examples of basic statements in JavaScript:
var x = 4;
var y = x * 4;
alert("Hello");
The two types of JavaScript statements
JavaScript statements come in two basic forms, simple and compound. I won’t spend a lot of time discussing statements because you don’t really need to know much about them. However, you should know the difference between simple and compound statements. A simple statement is just what you’d expect—it’s simple, like so:
x = 4;
A compound statement combines multiple levels of logic. An if/then/else conditional such as the one given here provides a good example of this:
if (something == 1) {
// some code here
} else {
// some other code here
}
No comments:
Post a Comment