JAVASCRIPT Flashcards
What is the purpose of variables?
to store data (short-term memory)
it can change or vary each time a script runs
How do you declare a variable?
var keyword var name;
ex: var quantity;
Var (old school), const, and let (if it’ll change)
How do you initialize (assign a value to) a variable?
quantity = 3;
What characters are allowed in variable names?
Upper or lowercase letter, dollar sign, or underscore
you can use numbers, but not as the first character
What does it mean to say that variable names are “case sensitive”?
if it is capitalized, you need to capitalize it always in order for it to be recognized as the same variable
What is the purpose of a string?
to store text (always within quotation marks) – letters and other characters
What is the purpose of a number?
counting, math, representing quantities, etc
- determining size of screen
- moving position of element on a page
- setting amount of time an element should take to fade in
What is the purpose of a boolean?
true/false values
What does the = operator mean in JavaScript?
It’s an assignment operator, not an ‘equal to’
How do you update the value of a variable?
use the equal sign. make sure it comes after the initial declaration
Why is it a good habit to include “labels” when you log values to the browser console?
it makes it clearer what variable is being logged and in what order
Give five examples of JavaScript primitives.
string number boolean null undefined symbol
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combines separate strings together to form one string
What purpose(s) does the + plus operator serve in JavaScript?
to add one value to another
concatenates
What data type is returned by comparing two values (, ===, etc)?
boolean (true or false)
What does the += “plus-equals” operator do?
it’s a shorthand for the addition assignment
if you know you are going to take the sum and add to it, you can use this
instead of x = x + y, it becomes x += y
What are objects used for?
group together a set of variables and functions to create a model of something
ex: object is hotel
What are object properties?
variables
ex:
- name:
- rooms:
- booked:
Describe object literal notation.
var object = { key: value, key: value, method; }
each is separated with a comma, except for the last one
How do you remove a property from an object?
delete object.property;
to clear the value:
object.property = ‘’;
What are the two ways to get or update the value of a property?
dot notation
object.property = new value;
brackets notation
object[‘property’].= new value
What are arrays used for?
working with a list or set of values that are related to each other. especially when you don’t know how many items/values there will be
Describe array literal notation.
var arrayName;
arrayName = [‘value’, ‘value];
var color = arrayName[0]
How are arrays different from “plain” objects?
arrays are numerically indexed, whereas object properties are alphanumerically indexed
What is the length property of an array?
checks how many items are in an array
var numColors = array.length
What is the length property of an array?
checks how many items are in an array, numerically
var numColors = array.length
What is a function in JS?
a series of statements we can call to perform a task
Why do we log things to the console?
- to help debug
- visualize the data
What is a method?
a function, which is a property of an object
How is a method different from any other function?
object that already contains a function definition
What is the difference between a parameter and an argument?
A parameter is the variable local to the function
The argument is the actual value itself that you are inputting into the function call
Why are function parameters useful?
parameters are placeholders and already hold the value of the argument
What two effects does a return statement have on the behavior of a function?
- Causes the function to produce a value we can use in our program.
- Prevents any more code in the function’s code block from being run.
How do you calculate the last index of an array?
last index = array.length - 1
What is a method?
a function, which is a property of an object
an object reference to a function?
How do you break a string up into an array?
string.split(separator)
ex: string.split(‘ ‘)
if you
How do you remove the last element from an array?
array.pop();
How do you round a number down to the nearest integer?
Math.floor();
Is the return value of a function or method useful in every situation?
yes but no
for example when you are using methods to change an array, you may want to double check what element you are deleting, but not necessarily
Roughly how many array methods are there according to the MDN Web docs?
40-ish
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
How do you break a string up into an array?
string. split(separator)
ex: string.split(‘ ‘)
Do string methods change the original string? How would you check if you weren’t sure?
no because the value is assigned to a different variable
you can console log the original string to make sure
Roughly how many string methods are there according to the MDN Web docs?
50
Is the return value of a function or method useful in every situation?
no