javascript Flashcards
Does a variable have to be declared and assigned at the same time?
No, you can give it a name and then later in the code assign it a variable
var a;
(then later)
a = 7
what do we put at the end of our code to signify that it is the end?
;
What is the assignment operator?
=
what does the assignment operator do?
it assigns a value to a variable name
what does console.log( ) do?
allows you to see things in the console.
console.log(a);
this will return the value of (a) in the console
a = 7
can you use console.log ( ) to see what variables were at specific points in your program? how?
yes, you can. You can place console.log ( ) both before and after the change of value and it will print out the different values for each assignment
a = 7
console.log(a)
a = ‘happy’
console.log(a)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
7
‘happy’
what does a not defined string or name cause?
an error
what is the value set to a variable name that has not been assigned a value?
undefined
how can you increment number values by one?
variableName++;
how can you lower number values by one?
variableName–;
what are decimal numbers called?
floats
what is the operator to find the remainder of two numbers?
%
10 % 2;
= 0 (no remainder)
11 % 3;
= 2 (remainder)
what do we often use the remainder operator for?
to figure out if a a number is even or odd. If we can divide a number by 2 and it returns a remainder of 0, then it is even.
What shorthand can you use to add a variable name to a number? For instance, a = a + 7.
+=
a += 7
What shorthand can you use to subtract a variable name to a number? For instance, a = a - 7.
-=
a-=7
What is it called when you use the shorthand to apply an arithmetic operator to a variable name? (ex: a += 12)
Compound assignment
What do we need to remember about what happens to the variable name when using Compound Assignment?
the new value becomes assigned to the variable name. It doesn’t just compute it to find the answer.
(ex) a = 2 a + 2 = 4 console.log(a) 2
b = 6
b += 2 = 8
console.log(b)
b = 8
How do we use Compound Assignment with multiplication?
*=
How do we use Compound Assignment with division?
/=
what are three different things that can enclose a string?
single quotes ‘ ‘
double quotes “ “
backticks ` `
When we are using double quotation marks to enclose a string, how do we use double quotation marks inside of our string without the engine interpreting it as the end of the string?
You use the escape character \ before the inside “ - this tells the engine that they are just quotation marks and not the end of the string.
what is a literal string?
it’s a group of characters that are enclosed in single, double quotes pr backticks. The engine doesn’t interpret anything inside the sting until it receives a matching closing quotation mark.
When using single quotation marks to enclose a sting, how do we use single quotation marks inside of our string without the engine interpreting it as the end of the sting?
You use the \ escape character, in the same way you would with double quotes.
what if you use one type of quotes to enclose a literal string and another type of quotes inside the string?
Then there is no problem. You do not need to use an escape character.
- ${stepsElements.join('\n\t')}
-
//
- wash //
- rinse //
- repeat //