JavaScript Flashcards
What is the purpose of variables?
to hold data (numbers, strings, booleans)
How do you declare a variable?
by creating a variable name
How do you initialize (assign a value to) a variable?
adding an equal sign next the variable name and then giving it a value/data
What characters are allowed in variable names?
letters, $, numbers but we shouldn’t use numbers
What does it mean to say that variable names are “case sensitive”?
it means that the capitalization needs to be the same in order to call that variable (ex. var myName and var MyName is two different variables)
What is the purpose of a string?
it holds the data type of letters and other characters
What is the purpose of a number?
it holds the data type of numbers (integers, decimals, etc)
What is the purpose of a boolean?
it holds the data type of one of two values, true or false
What does the = operator mean in JavaScript?
a value is being assigned to a variable
How do you update the value of a variable?
by assigning it to a new value
What is the difference between null and undefined?
null is subject to change, there is nothing but it could change into something. while undefined is literally nothing
Why is it a good habit to include “labels” when you log values to the browser console?
so that you won’t get confused to what is being logged
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
when two or more strings are added together
What purpose(s) does the + plus operator serve in JavaScript?
used to add one value to another
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
it adds and re-assigns a new value to a variable
What are objects used for?
to hold a set of variables that all link to one thing/object
What are object properties?
it tells us about the object, stores info ab the object (ex. name:, age:,)
Describe object literal notation.
an array of keys and values
How do you remove a property from an object?
using the delete operator
What are the two ways to get or update the value of a property?
using a dot notation or bracket notation (ex. example.name, example[‘name’])
What are arrays used for?
to store multiple values
Describe array literal notation.
values within brackets [ ]
(ex. var colors = [‘red’, ‘white’, ‘blue’]
How are arrays different from “plain” objects?
arrays store actual variables in an index starting from 0
What number represents the first index of an array?
0
What is the length property of an array?
it shows the amount of variables inside of an array
How do you calculate the last index of an array?
by subtracting the length of an array by 1
(ex. var lastIndex = example.length -1;)
What is a function in JavaScript?
it is a “power” tool, it is used to run a sequence of code when it is called
Describe the parts of a function definition.
a function definition is the name used for that function so you have something to call it, also contains parameters
(ex. function sayHello(name) {} )
Describe the parts of a function call.
you can call a function using the function definition and parenthesis (ex. sayHello(‘Tim’) )
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call has the value inside(a parameter) the parenthesis while the function definition has a variable (argument) inside
What is the difference between a parameter and an argument?
a parameter is like a placeholder for the value like a variable, an argument has a value. when we define a function we declare a parameter, when we call a function we pass it arguments
Why are function parameters useful?
it’s a placeholder so that we know what will come out as an argument
What two effects does a return statement have on the behavior of a function?
it produces a value for us to use and it prevents any more code in the function’s code block to run
Why do we log things to the console?
so that we able to see what the code is producing
What is a method?
it is a function which is a property of an object
How is a method different from any other function?
methods are associated with objects while function just performs a task when called
How do you remove the last element from an array?
using the pop() method
How do you round a number down to the nearest integer?
using the Math.floor() method
How do you generate a random number?
using the Math.random() method
How do you delete an element from an array?
using the slice() , pop(), shift() method
How do you append an element to an array?
using the push() method
How do you break a string up into an array?
using the split() method
Do string methods change the original string? How would you check if you weren’t sure?
string methods doesn’t change the original string. to double check you can log it to the console
Roughly how many string methods are there according to the MDN Web docs?
about 50
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
about 40
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.
!=, ===, <, >, <=, >=, !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
so that the code will only run if the requirements are met
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (x = y) {
return ‘yay;
}
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
by using a logical operator && or | |
What is the purpose of a loop?
to run code over and over until the outcome is false or when it is capped
What is the purpose of a condition expression in a loop?
to see if the expression is true or not so it knows when to stop
What does “iteration” mean in the context of loops?
a sequence of code run repeatidly
When does the condition expression of a while loop get evaluated?
after the initialization expression
When does the initialization expression of a for loop get evaluated?
after the incrementation in the final expression or at the beginning of the iteration if it is the first time