JavaScript Flashcards
JavaScript Primitives and Variables:
What is the purpose of variables?
to store data for the future action/reference
JavaScript Primitives and Variables:
How do you declare a variable?
variable keyword
variable name ;
JavaScript Primitives and Variables:
How do you initialize (assign a value to )a variable?
(variable keyword
variable name)
assignment operator (=)
variable value ;
JavaScript Primitives and Variables:
What characters are allowed in variable names?
letters, dollar sign, underscore (only first three can start the variable name) and numbers (no dashes or periods)
JavaScript Primitives and Variables:
What does it mean to say that variable names are “case sensitive”?
it means that there’s a difference between a word starting with lowercase and that same word starting with a capital letter.
(bad practice to have same name using difference cases)
JavaScript Primitives and Variables:
What is the purpose of a string?
Strings are used when working with text
(typically used to add new content to a page and can contain HTML markup)
JavaScript Primitives and Variables:
What is the purpose of a number?
Numbers are used in tasks that involve counting or calculating sums
JavaScript Primitives and Variables:
What is the purpose of a boolean?
Booleans are used to determine which parts of a script should run.
Used to make decisions
JavaScript Primitives and Variables:
What does the = operator mean in JavaScript?
The equal sign means that you are going to assign a value to a variable
JavaScript Primitives and Variables:
How do you update the value of a variable?
variable name
assignment operator
and then the new value ;
JavaScript Primitives and Variables:
What is the difference between null and undefined?
null intentional absence of a value
undefined creates a variable but assigns it no value
JavaScript Primitives and Variables:
Why is it a good habit to include “labels” when you log values to the browser console?
If you do not include “labels” it can be confusing
JavaScript Primitives and Variables:
Give five examples of JavaScript primitives
number, string, boolean, null, undefined
JavaScript Operators and Expressions:
What data type is returned by an arithmetic operation?
numbers
JavaScript Operators and Expressions:
What is string concatenation?
the process of joining together two or more strings to create one new string
JavaScript Operators and Expressions:
What purpose(s) does the + plus operator serve in JavaScript?
the plus operator adds numbers together or concatenates
JavaScript Operators and Expressions:
what data type is returned by comparing two values (<, >, ===, etc)?
boolean
JavaScript Operators and Expressions:
What does the += “plus-equals” operator do?
it adds the value to the right of the operand to a variable and assigns the result to the variable
JavaScript Objects:
What are objects used for?
group together a set of variables and functions to create a model of something you recognize in the real world
JavaScript Objects:
what are object properties?
variables that give information about an object
JavaScript Objects:
Describe object literal notation.
{
key: value ,
}
JavaScript Objects:
How do you remove a property from an object?
delete operator followed by objectName.propertyName
(period is member operator)
JavaScript Objects:
What are the two ways to get or update the value of a property?
dot notation or square bracket notation
JavaScript Arrays:
What are arrays used for?
for lists of data where either the order of the list is extremely important or unimportant
JavaScript Arrays:
Describe array literal notation
[item, item, etc]
JavaScript Arrays:
How are arrays different from ‘plain’ objects?
all arrays have length property
objects do not have an order
(automatically updates as you add things. Arrays, you call a method to add items. Objects, you assign values directly to property)
JavaScript Arrays:
What number represents the first index of an array?
[0]
JavaScript Arrays:
What is the length property of an array?
property.length
get the number of items in the array
JavaScript Arrays:
How do you calculate the last index of an array?
subtract 1 from property.length
JavaScript Functions:
What is a function in JavaScript?
chunk of code that performs a task that returns something (most the time)
JavaScript Functions:
Describe the parts of a function definition
functionKeyword optionalFunctionName (parameters) {function code block optionalReturnStatement} end of function code block
JavaScript Functions:
Describe the parts of a function call
functionName(arg1, arg2, etc);
JavaScript Functions:
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function definition has the functionKeyword and a code block, function call does not
JavaScript Functions:
What is the difference between a parameter and an argument?
parameters are part of a function declaration and act as placeholders
arguments are part of function call and take the place of parameters
JavaScript Functions:
Why are function parameters useful?
they act as placeholders for arguments
JavaScript Functions:
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
JavaScript If:
Give 6 examples of comparison operators
strictly equal to (===), strictly not equal to (!==), greater than, less than, greater than or equal to, less than or equal to, equal to (==)
JavaScript If
What data type do comparison expressions evaluated to?
boolean
JavaScript If
What is the purpose of an if statement?
to make decisions
JavaScript If:
Is else required in order to use an if statement?
no
JavaScript If:
Describe the syntax(structure) of an if statement?
if keyword, condition,
JavaScript If:
What are the three logical operators?
logical and (&&), logical or (||), logical not (!)
JavaScript If:
How do you compare two different expressions in the same condition?
logical and
logical or
JavaScript Methods:
Why do we log things to the console?
logging things into the console helps with debugging, so we can see where the browser prints errors and warnings in our code
JavaScript Methods:
What is a method?
A method is a function which is a property of an object
JavaScript Methods:
How is a method different from any other function?
methods are associated with objects
JavaScript Methods:
How do you remove the last element from an array?
pop()
JavaScript Methods:
How do you round a number down to the nearest integer?
Math.floor()
JavaScript Methods:
How do you generate a random number?
Math.random()