JavaScript Flashcards
What is the purpose of variables?
To store data/information
How do you declare a variable?
declaring the variable and giving it a name
How do you initialize (assign a value to) a variable?
by the ‘=’ (assignment operator) and giving it a value
What characters are allowed in variable names?
letters , $ , _ (underscore) , and numbers but can’t start with numbers
What does it mean to say that variable names are “case sensitive”?
capital and lowercase letters affect the name. You can have variables spelled the same but with different capitalization
What is the purpose of a string?
storing text / using any series of characters
What is the purpose of a number?
to store numbers for calculations / do math / represent numerical values
What is the purpose of a boolean?
it only has 2 values / used to determine what part of a script should run
What does the = operator mean in JavaScript?
Assignment operator / used to assign variables to data
What is the difference between null and undefined?
null is intentional / while undefined is something you didn’t calculate
Why is it a good habit to include “labels” when you log values to the browser console?
so you know what you are logging
Give five examples of JavaScript primitives.
undefined, null, boolean, string, number
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining 2 or more strings
What purpose(s) does the + plus operator serve in JavaScript?
it is an arithmetic operator and you can use it with adding numbers / also concatenate strings
What data type is returned by comparing two values (, ===, etc)?
a boolean
What does the += “plus-equals” operator do?
it adds the value on the right to the left value
What are objects used for?
group together a set of variables and functions
combining like data (cars, person)
What are object properties?
variable that is part of an object
Describe object literal notation.
easiest way to create an object
variable declaration with name and assign it a value of {} with properties and methods inside
How do you remove a property from an object?
delete objectName followed by the property name
What are the two ways to get or update the value of a property?
the dot notation and bracket notation
What are arrays used for?
to store a list of items / values
Describe array literal notation.
var name = [] / var variable with the name assignment operator with square brackets and properties inside
What number represents the first index of an array?
0
What is the length property of an array?
property that tells you how long an array is
How do you calculate the last index of an array?
by subtracting 1 from the length
How are arrays different from “plain” objects?
they maintain order
What is a function in JavaScript?
a reusable line of code that can do multiple things
Describe the parts of a function definition.
function keyword to create the function optional name parenthesis with an parameter or if multiple separate with comma start of the code block with { optional return statement at the end end of the code block with }