Main deck Flashcards
What are “var, let, const”?
Declaration Keywords
What does var do?
Declares a variable of global scope
What does let do?
Declares a variable of block scope
What does const
do?
Declares a variable that cannot be reassigned.
What does it mean to “declare a variable”?
It means telling the computer to open a slot in memory where it can place a value in the future.
What can be stored in a variable?
Any “value” - numbers, strings, booleans, objects, etc.
What are the 5 basic (or “primitive”) data types?
Number, string, boolean, undefined, null
What’s the difference between ‘5’ and 5?
The first one is a string and the second one is a number.
What does var x = 5
do?
Declares a variable called x and assigns the value 5 to it.
Are semicolons required in javascript?
No but it’s a good idea to use them.
What should the file extension be for a javascript file?
.js
How do you get to a javascript console in terminal?
node
What are the boolean values?
true and false
What does (5+2) resolve to?
10
What is the operator =
called?
The assignment operator
What does the operator =
do?
Assigns the value on the right to the variable on the left.
What are all these called: =
, +
, -
, ==
, %
, !
, !=
Operators
What category of operators are all these: ==
, &&;&&;
, ||
, !=
Boolean operators
What is the operator ==
called?
The comparison operator
What does the operator ==
do?
Compares both sides and returns true if they are equal (but not necessarily the same type).
What is the operator ===
called?
“True equals” or “strict comparison” operator.
What does the operator ===
do?
Compares both sides and returns true if they are equal (AND the same type!).
What does the operator !=
do?
Returns true if the two sides are NOT equal.
What is the operator !
called?
The negation operator (often called “NOT”).
What does the operator !
do?
Flips (“negates”) the boolean value…true turns to false and false turns to true.
What does !!true && true
resolve to?
true
What does !(true || false) && !(true && false)
resolve to?
false
How are parentheses used in programming?
Just like in math - they tell the computer to resolve everything inside the parentheses before doing anything else.
Are you required to assign a value to a variable when you declare it?
No - you can write var x
and that will declare the variable and the value will be undefined.
What value does a variable have before you assign a value to it?
undefined
What’s the difference between var and let?
var gives you a variable with global scope and let gives you a variable with block scope
What does it mean if a variable has global scope?
The variable can be used anywhere in the file.
What does it mean if a variable has block scope?
The variable can only be used inside the block where it is declared.
What is a “block”?
Code that is surrounded by { and } (curly braces)
What is the operator %
called?
Modulus
What does the operator %
do?
Computes the remainder of the number on the left when you divide it by the number on the right.
What does the operator >=
do?
Returns true if the number on the left is greater than or equal to the number on the right.
What does "5"+10
resolve to?
510
(it converts the number 10 to string “10” before adding - this is called type coercion)
What are two names for the following code: if (...) {... }
“If statement” and “conditional statement”
What does syntax mean?
Syntax means the way something is written in code.
What is the syntax for a conditional/if statement?
if (condition) {
…
}
What is the stuff inside the parentheses in an if statement called?
The condition
What does an if statement do?
Tells the computer to only execute the code inside the block if the condition is true.
What will be logged on the console for the following code? let x = 5; if (x == 5) { console.log('marko is a boss'); } else { console.log('raymond is a boss'); }
marko is a boss
What will be logged on the console for the following code? let x = 5; if (x >= 6 || x <= 4) { console.log('marko is a boss'); } else { console.log('raymond is a boss'); }
raymond is a boss
In a conditional statement, when is an “else if” block of code executed?
If the first condition was false but the condition after “else if” was true.
In a conditional statement, when is an “else” block of code executed?
When the condition was false.
What is the syntax of a for loop?
for (iterator declaration; iterator condition; iterator mutation) {
….
}
In a for loop, you always declare a variable right after the for
keyword. What is that variable called in general?
The iterator
What does it mean to “iterate” over an array?
To loop through the values of the array with a for loop.
What is an object?
A collection of properties grouped together in one variable name.
What is the syntax to declare a variable and assign an empty object to it?
let myObject = {};
What is the syntax for accessing a property called “color” in an object called “paint”?
paint.color or paint[‘color’] (notice the quotes in the second one)
Suppose you declare an object let x = {color:'green', size:10};
. What are “color” and “size” called?
Keys or properties
Suppose you declare an object let x = {color:'green', size:10};
. What are “color” and “size” called?
Values
What is an array?
A list of values grouped together in one variable name.
Suppose you declare an array let myArray = [1,2,3]
. What does myArray[1]
resolve to?
2 (because the index starts at zero)
Suppose you have an array called myArray. In the code myArray[6]
, what is the stuff inside the square brackets called?
The index
When you have a variable or object called myObject, using the .
(dot) operator allows you to…
access any of the object’s properties or methods.
What is a method?
A function attached to an object or variable.
What is a function?
A block of code that you can reuse by replacing the arguments with any value you want.
Does a function have to have arguments?
No
Does a function have to return something?
No
If a function accepts something as input, the input(s) are called…
argument(s)
How does a method differ from a function?
A method is just a function that is attached to a variable, so it does something with the variable it is attached to.