JavaScript Flashcards
What is the purpose of variables?
a vehicle to have permanence of data
How do you declare a variable?
var keyword
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letters, number $ and _
What does it mean to say that variable names are “case sensitive”?
uppercase =/= lowercase
What is the purpose of a string?
to hold text
What is the purpose of a number?
for math
What is the purpose of a boolean?
for conditionals, to make decisions
What does the = operator mean in JavaScript?
value is being assigned to
How do you update the value of a variable?
reassign new value (=)
What is the difference between null and undefined?
Null is an assigned value without value, undefined has never been assigned
Why is it a good habit to include “labels” when you log values to the browser console?
for context in the output
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
A number
What is string concatenation?
joining strings together
What purpose(s) does the + plus operator serve in JavaScript?
concatenation or addition
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What are objects used for?
To store multiple variables under one name
What are object properties?
individual piece of named data within an object
Describe object literal notation.
var object = {} with commas after each new variable
How do you remove a property from an object?
with the delete operator
What are the two ways to get or update the value of a property?
dot or square bracket notation
What is a function in JavaScript?
A repeatable set of actions with a specific name
Describe the parts of a function definition
Function keyword with the name of the function followed by () with optional parameters inside, curly braces with code inside and a return statement to give back a value
Describe the parts of a function call
Function name, (), with optional arguments inside the parentheses
When comparing them side by side, what are the differences between a function call and a function definition
A function call has just the name with the arguments inside the following parentheses. Whereas the definition has the word function followed by the functions name and parameters inside the parenthesis with a following code block containing a return
What is the difference between a parameter and an argument?
parameter is in the function definition. argument is the real data being passed to the function
Why are function parameters useful?
it allows you to have variance in the application of the function
Why do we log things to the console?
debugging, verification
What is a method?
A function in an object
How is a method different from any other function?
Function inside an object rather than by itself. function() vs obj.method()
How do you remove the last element from an array?
pop() method
How do you round a number down to the nearest integer?
Math.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()
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, console log to check
Give 6 examples of comparison operators.
==, !=, ===, >, <, >=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
allows us to take decisions in our code
Is else required in order to use an if statement?
no
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
and, or