Part 1- A Smarter Way to Learn JavaScript Flashcards
What’s the code to declare a variable?
var variableName = “text string defining variable”;
Do you have to assign a value to a variable when you declare it?
No. You can assign a value to it later.
When you are assigning a new value to a variable that has already been declared, do you have to use var?
No. You only use var when you are declaring a variable
Can you use a number for a variable name?
No. Your variable name can have numbers in it, but it cannot start with a number. It must start with a letter, or $ or _
A number cannot be used in equations if it has what?
Quotation marks around it, because then it would be a string.
Can a variable be used in calculating its own new value?
Yes, such as:
var x = 90;
x = x + 1;
What’s wrong with this variable? var propertiesOf”It”?
It has quotes. A variable cannot have quotes.
How do you tell is something is a variable? (list two things)
*it’s not a JavaScript keyword, like alert
*it’s an alphabet letter or word
Are variables case sensitive?
Yes, variables are case sensitive.
Which characters can be in a variable?
*letters
*numbers (though not at the beginning of the variable name)
*dollar sign
*underscore
Can a variable contain a space?
No. Variables cannot contain a space.
Can a variable contain a JS keyword as part of the variable?
Yes. You could use myAlert for example, but not just alert.
What does this operator do and what’s it called?
%
*Modulus
*returns the remainder of a division statement
Incrementors after the variable
When the ++ comes afterwards…
x = y++
…then incrementing happens after the assignment of y’s value to x. So the X gets left out of the increase:
1) x becomes what y is
2) y is then incremented
Incrementors before the variable
When the ++ comes before…
x = ++y
…then incrementing happens before the assignment, so the first variable shares the wealth.