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 don’t include “labels” it can get confusing
labels describe the variable or value being logged
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?
it’s when you join two or more strings to create one new string
(if you concatenate other data types with a string, it’ll be a string)
JavaScript Operators and Expressions:
What purpose(s) does the + plus operator serve in JavaScript?
the plus operator adds numbers together or concatenates strings together
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 that is recognizable 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 keyword 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?
they are used to store a list of values/data
(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?
arrayVariable.length
get the number of items in the array
JavaScript Arrays:
How do you calculate the last index of an array?
subtract 1 from the array’s 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)
{ (opening curly brace for the function code block)
function code block optionalReturnStatement
} (closing curly brace for the function code block)
JavaScript Functions:
Describe the parts of a function call
functionName(arg1, arg2, etc);
- zero or more arguments separated by commas inside parenthesis
JavaScript Functions:
Describe the parts of a function call
functionName(arg1, arg2, etc);
- zero or more arguments separated by commas inside parenthesis
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 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() method
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()
JavaScript Methods:
How do you delete an element from an array?
splice()
JavaScript Methods:
How do you append an element to an array?
push()
JavaScript Methods:
How do you break a string up into an array?
str.split()
JavaScript Methods:
Do string methods change the original string? How would you check if you weren’t sure?
doesn’t change the string
console.log to check
JavaScript Methods:
Roughly how many string methods are there according to the MDN Web docs?
36
JavaScript Methods:
Is the return value of a function or method useful in every situation?
no