Math Expressions: unfamiliar operators Flashcards
Code a short form of x = x + 1; Use either of the two legal expressions.
x++; or ++x;
If x has a value of 100, what is the fastest way to reduce it to 99 with a math expression? Use either of the two legal expressions.
x–; or –x;
var x = 50; var y = x++; What is the value of y?
50
var x = 50; var y = --x;
49
In a single statement, increment the variable num and assign its new value to a second variable, newNum, which hasn’t been declared beforehand.
var newNum = ++num;
In a single statement, decrement num and assign its original value to newNum, which hasn’t been declared beforehand.
var newNum = num–;
Using minimal code, decrement x. Use either of the two legal expressions.
x–; or –x;
What is the long version of x++?
x = x + 1;
In a single statement subtract 1 from a variable and assign the new value to another variable, which hasn’t been declared beforehand. Both variables wind up with the same value.
var newNum = –num;
In a single statement add 1 to a variable and assign its original value to another variable, which hasn’t been declared beforehand.
var newNum = num++;
Increment a variable. Use either of the two legal expressions. In a second statement, display its new value in an alert.
num++; or ++num;
alert(num);