JavaScript Editor Free JavaScript Editor     JavaScript Debugger 




Main Page

Previous Page
Next Page

14.3. Operators

Regardless of the language, there is usually some commonality. There's addition, subtraction, multiplication, division, and assignment. In some languages, including Ruby and JavaScript, the addition operator does double duty as the concatenation operator. This means that examples such as the following are pretty much the same, regardless of the language:

X = 1 + 1
X = 1  1
X = 1 * 1
X = 1 / 1

However, occasionally will you see something a little out of the ordinary, usually in languages that borrow some of their syntax from C. In Ruby, they're called multiple assignments; I like to think of them as less typing. Consider, for a moment, the following line of code:

X = X + 5

All that it does is increment the variable X by 5, so wouldn't it be easier to type this instead?

X += 5

Yeah, all that I'm saving is two keystrokes, the second X and a space, but it adds up. Imagine for a moment the variable name was my last name, Woychowsky instead of X. Having to type it only once would greatly extend the life of the W key. The same shortcut is available for subtraction, multiplication, and division.


Previous Page
Next Page

http://www.cashadvance-loans.net/pennsylvania/cash-advance-harrisburg-pa/


JavaScript Editor Free JavaScript Editor     JavaScript Debugger


©