木曜日, 2月 02, 2006

More JavaScript

Expressions and Operators
Now that we're learning about data, we need to understand what an expression is:
An expression is any combination of variables, constants, operators and/or method calls that, when evaluated, can be reduced to a single value.

We've learned about variables and constants already. Now its time to learn about the operators we can use in the expressions.

String Concatenation Operator
String literals and string variables can be joined together to make longer strings by using the string concatenation operator -- a plus sign (+). The result is a string expression. Here are some examples:
var temp="hot";
var temp="shot";
document.write("the coffee is "+temp);
alert("The engineer is a real" +temp+word);
window.status="Today is a "+temp+ "day!";
var ans= confirm(temp+" or cold?");

Each of these examples, contains a string expression. Notice that some are string literals and variables using the concatenation operator. string expressions may be used wherever a string value is needed (why? because an expression always evaluates to a string value!) Try these examples in one of your test programs to see what the results are.

0 Comments:

コメントを投稿

Links to this post:

リンクを作成

<< Home