JavaScript Flashcards
What is the purpose of variables?
To store information
How do you declare a variable?
using var before the variable name
syntax
How do you initialize (assign a value to) a variable?
variableName = value
What characters are allowed in variable names?
alphabet, number, $ and _ (variable should not start with a number)
What does it mean to say that variable names are “case sensitive”?
uppercase and lowercase variable names are considered differently
What is the purpose of a string?
to store text information
What is the purpose of a number?
to store numbers
What is the purpose of a boolean?
to make a decision in a code (either true or false)
What does the = operator mean in JavaScript?
= means assigning value to a variable
How do you update the value of a variable?
variablename = newValue
What is the difference between null and undefined?
undefined variable means a variable has not been assigned any value by the user
null means variable is assigned by the user with a null value
Why is it a good habit to include “labels” when you log values to the browser console?
To know which variable is being printed is a console
Give five examples of JavaScript primitives.
number, string, boolean, symbol & bigint.
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
joining two separate strings to one
What purpose(s) does the + plus operator serve in JavaScript?
adding numbers or concating two or more string
What data type is returned by comparing two values (, ===, etc)?
Boolean data type
What does the += “plus-equals” operator do?
\+= means adding value and storing to same variable eg(variableName = VariableName + 'additionalString')
What are objects used for?
to store multiple data and different types of data
What are object properties?
variable store in object
Describe object literal notation.
eg {propert:value}
How do you remove a property from an object?
using delete operator followed by object.property
syntax (delete objectname.propertyname)
What are the two ways to get or update the value of a property?
dot notaion and bracket
eg
objectname.updateProperty = newValue
objectname[‘updateProperty’] = newValue
What are arrays used for?
To store a list of data of similar type
Describe array literal notation.
syntax arrayVariableName = [data1, data2, data_n];
How are arrays different from “plain” objects?
does not have key or property
What number represents the first index of an array?
zero 0
What is the length property of an array?
number of data in the array represent the length
How do you calculate the last index of an array?
arrayVariableName.length - 1
What is a function in JavaScript?
block od code that can be reused again and again
Describe the parts of a function definition.
function keyword, function name, parameter ,code block, and return
Describe the parts of a function call.
functionName(“argument-If-Any”)
When comparing them side-by-side, what are the differences between a function call and a function definition?
call would be without function keyword
What is the difference between a parameter and an argument?
the argument has actual value
Why are function parameters useful?
pass information or instructions into functions
What two effects does a return statement have on the behavior of a function?
Produce a value & exit the function
Why do we log things to the console?
to label the return
What is a method?
the method is a function on an object
How do you remove the last element from an array?
variableName.pop method
How do you round a number down to the nearest integer?
variableName.floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice()
How do you append an element to an array?
push() unshift()
How do you break a string up into an array?
split()
Do string methods change the original string? How would you check if you weren’t sure?
no string is immutable and we can use console log to check
Roughly how many string methods are there according to the MDN Web docs?
a Lot of
Is the return value of a function or method useful in every situation?
its usefull but not in all case
Roughly how many array methods are there according to the MDN Web docs?
36 methods