JavaScript Flashcards
What is the purpose of variables?
to store data and use it later
How do you declare a variable?
by putting var ____ < name
How do you initialize (assign a value to) a variable?
use the equal operator it represents the word “assignment”
What characters are allowed in variable names?
lowercase, numbers, dollar sign, underscore. No dash(-) or (.), also do not start with a number. Start with either a letter, dollar sign, or underscore
What does it mean to say that variable names are “case sensitive”?
score and Score are considered different variables (DO NOT DO THIS)
What is the purpose of a string?
To write characters and words
What is the purpose of a number?
To give data
What is the purpose of a boolean?
It is an on off switch that can be used to determine whether something should run in a script
What does the = operator mean in JavaScript?
it means assignment
How do you update the value of a variable?
The var keyword isn’t necessary but you simply reassign it later in the document.
What is the difference between null and undefined?
null is an intentional way of saying nothing, undefined is the way the computer says nothing. Every null value you see is purposeful.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels provide clarity for other people and for you in the future.
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
numeric data type, some sort of number
What is string concatenation?
string concatenation is taking two strings together and gluing them to make a new string
What purpose(s) does the + plus operator serve in JavaScript?
arithmetic operations, string operations (concatenating)
What data type is returned by comparing two values (, ===, etc)?
boolean data types
What does the += “plus-equals” operator do?
it’s shorthand
motto+= ‘is the goat’;
motto=motto + ‘is the goat’;
they are the same, the way you read the second line is what the first one is doing
What are objects used for?
objects group together variables and functions
What are object properties?
Object properties are keys and values
Describe object literal notation.
object literals itself is the curly braces
How do you remove a property from an object?
use the delete operator object.property
What are the two ways to get or update the value of a property?
bracket notation and dot notation
anything that follows the dot notation is a string
bracket notation lets you check for an expression when accessing a property
What are arrays used for?
a list or a set of values related to each other. Especially useful if you aren’t sure how big the list will be. Also the keys are indexed automatically with a number.
Describe array literal notation.
var \_\_\_ = [ ]; the curly braces is the literal part
How are arrays different from “plain” objects?
arrays have an index automatically instead of a key, it also has a length property.
What number represents the first index of an array?
[0]
What is the length property of an array?
it stores the knowledge of how many values are in it.
How do you calculate the last index of an array?
length - 1 is how you calculate the last index of an array.
What is a function in JavaScript?
A function is a reusable part of code.
Describe the parts of a function definition.
Function has a keyword, optional name of the function. () that hold optional parameter list
{code block} return statement
Describe the parts of a function call.
A function name followed by a list of parameters
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition features a keyword and a codeblock. A call has the arguments.
What is the difference between a parameter and an argument?
Parameter is an unknown placeholder type that’s holding a spot for an eventual there (the argument).
Why are function parameters useful?
parameters allow us to leave a spot open for a value and call and get different results. You create adaptive behavior
What two effects does a return statement have on the behavior of a function?
Returns a value and ends the function
Why do we log things to the console?
console log is for debugging, it’s only for developers. When you have an issue you should log all your values.
What is a method?
a method is a function that is a property of an object.
How is a method different from any other function?
Methods are functions that are part of objects. Other then that methods and functions are interchangeable (in javascript)
How do you remove the last element from an array?
The pop method.
How do you round a number down to the nearest integer?
Call the floor method
How do you generate a random number?
The random method of the math object
How do you delete an element from an array?
splice method
How do you append an element to an array?
push (append means add to the end)