JavaScript Flashcards
What is the purpose of variables?
Variable is a container for a value, like a number we might use in a sum, or a string that we might use as a part of a sentence.
How do you declare a variable?
We type the keyword (var, let, const) followed by the name you want to call your variable.
How do you initialize (assign a value to) a variable?
First type the variable name, followed by the equals sign(=), followed by the value you want to give it.
Example: var firstName = ‘Dylan’;
What characters are allowed in variable names?
letters, numbers (cannot start with a number!) dollar sign($), or an underscore
What does it mean to say that variable names are “case sensitive”?
Variable names care about the case sensitivity of their names, meaning a variable named score and Score would be different because of the capitalization of the letter S in score.
What is the purpose of a string?
Strings are pieces of text, they must be wrapped within quote marks.
What is the purpose of a number?
calculating numbers, doing math stuff
What is the purpose of a boolean?
True or False values, they are generally used to test a condition, after which code is run as appropriate.
What does the = operator mean in JavaScript?
1 equal sign is used for assignment of variables
How do you update the value of a variable?
Once the variable has been initialized, you can change (or update) that value by giving it a different value.
What is the difference between null and undefined?
Null means empty can only be assigned, undefined means a variable is declared but has no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
A label in the console.log is a simple way to describe the variable or value being logged.
Give five examples of JavaScript primitives:
string, number, boolean, null, and undefined
What data type is returned by an arithmetic operation?
single numerical value (number)
What is string concatenation?
the process of appending one string to the end of another string and so on.
What purpose(s) does the + operator serve in JavaScript?
- addition in math
- string concatenation
What data type is returned by comparing two values (< , > , === . etc)?
boolean ( true or false )
What does += “plus equals” operator do?
+= or “plus-equals” adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator.
What are objects used for?
It is used to store various keyed collections and more complex entities
What are object properties?
Properties are the values associated with a JavaScript object.
Describe the object literal notation:
The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array. Values created with anonymous functions are methods of your object.
How do you remove a property from an object?
delete operator
What are two ways to get or update the value of an object property?
dot notation and bracket notation
What are arrays used for?
Storing a collection of multiple items under a single variable name
Describe the array literal notation:
var arrayName = [ ];
separate indexes by commas
How are arrays different from “plain” objects?
Arrays have an order, stored within square brackets, have numeric indexes
What number represents the first index of an array?
0
What is the length property of an array?
returns the length of the array (counts each index and returns number value)
How do you calculate the last index of an array?
var variableName = array[array.length - 1]
subtract 1 from length of the array
Describe the parts of a function definition:
function (keyword) optionalName(parameters){ (code) return };
Describe the parts of a function call
functionName(arguments,arguments);
-arguments are optional
When comparing them side-by-side, what are the differences between a function call and a function definition?
What is the difference between a parameter and an argument?
Why are function parameters useful?
they provide placeholders when writing code
What two effects does a return statement have on the behavior of a function?
1) it exits the functions code block
2) it gives back a value
Why do we log things to the console?
console.log is a debugging tool to check for errors
What is a method?
a method is a function which is a property of an object
How is a method different from any other function?
- methods are functions
- methods are attached to an object
How do you remove the last element from an array?
.pop()
How do you round a number down to the nearest integer?
math.floor()
How do you generate a random number?
math.random()
How do you delete an element from an array?
.splice()
How do you append an element to an array?
.push()
How do you break a string up into an array?
.split()
Do string methods change the original string? How would you check if you weren’t sure?
They remain the same unless you assign it to a new variable. You can check by console.log()
Roughly how many string methods are there according to the MDN web docs?
around 30 string methods
Is the return value of a function or method useful in every situation?
NO
Roughly how many array methods are there according to MDN web docs?
around 25 array methods
What three-letter acronym should you always include in your Google search about a javaScript method or CSS property?
MDN
Give 6 examples of comparison operators:
Is Equal to (==) is not equal to (!=) Greater than (>) Less than (=) Less than or equal to (<=)
What data type do comparison expressions evaluate to?
Booleans (true or false)
What is the purpose of an IF statement?
If statement is a decision-making statement that guides a program to make decisions based on specified criteria.
is ELSE required in order to use an IF statement?
NO
Describe the syntax of an IF statement:
if (condition) { return}
What are the three logical operators?
Logical And (&&) Logical Or (||) Logical Not (!)
How do you compare two different expressions in the same condition?
Logical And (&&) or Logical OR (||)
What is the purpose of a loop?
A loop is a programming structure that repeats a sequence of instruction until a specific condition is met.
What is the purpose of a condition expression in a loop?
to check if the code needs to keep iterating
What does “iteration” mean in the context of loops?
repetition of the for loop code block
When does the condition expression of a while loop get evaluated?
before each iteration of the loop
When does the initialization expression of a for loop get evaluated?
BEFORE ANYTHING , ONLY HAPPENS ONE TIME, it happens in the beginning
When does the condition expression of a FOR loop get evaluated?
after initialization, before each iteration the condition is checked to allow the loop to get running until condition is met.
When does the final expression of a FOR loop get evaluated?
at the end of each iteration and before the condition is checked again.
Besides a RETURN statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
BREAK
What does the ++ increment operator do?
Adds one (value of variable goes up by 1 and assigns that to new variable)
ex. var i = 0
i++
i now equals 1.
How do you iterate through the keys of an object?
FOR IN loop
Why do we log things to the console?
We use it to debug our code and log our progress
What is a ‘model’?
Example of a structure, representation of an object