JavaScript Flashcards
What is the purpose of variables?
data storage
How do you declare a variable?
var name;
How do you initialize (assign a value to) a variable?
variable name = variable value;
What characters are allowed in variable names?
letters, numbers, $, underscore
What does it mean to say that variable names are “case sensitive”?
two variables can share the same name but have different capitalization, making them different variables (don’t do this; it’s bad practice)
What is the purpose of a string?
storage of text data
What is the purpose of a number?
storage of numeric data types
What is the purpose of a boolean?
to make decisions
What does the = operator mean in JavaScript?
assignment operator
How do you update the value of a variable?
variable name = new value;
What is the difference between null and undefined?
- null: intentional absence created by a human
- undefined: lack of value recognized by JavaScript
Why is it a good habit to include “labels” when you log values to the browser console?
for clarity and to describe the variable or value being logged
Give five examples of JavaScript primitives
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
numeric
What is string concatenation?
adding two or more strings together to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
arithmetic, concatenation
What data type is returned by comparing two values (< , > , ===, etc.)?
boolean
What does the += “plus-equals” operator do?
adds another value to variable and the result of that expression gets assigned to the variable
What are objects used for?
to group together a set of variables and functions
What are object properties?
variables
Describe object literal notation
var object = {
};
How do you remove a property from an object?
by using the delete operator
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What are arrays used for?
store lists of data
Describe array literal notation
var name = [ ];
How are arrays different from “plain” objects?
only uses numeric index, contains a length property that is constantly updated, multiple methods to interact with arrays
What number represents the first index of an array?
0 (zero)
What is the length property of an array?
stores (true) count of number of items are in array
How do you calculate the last index of an array?
subtract 1 from the variable
What is a function in JavaScript?
a set of code block for performing a task that is reusable
Describe the parts of a function definition
function keyword, name, parameters list, {code block};
Describe the parts of a function call
function name(arguments);
there can be 0 to many arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call: there is a function name followed by (); - executes code
function definition: there is a function keyword and a code block
- code does not run
- gives function a name
What is the difference between a parameter and an argument?
parameter: placeholder for argument value
- value is unknown until function gets called and argument(s) is passed
argument: a known value that gets passed when a function is called
Why are function parameters useful?
- serves as a placeholder for arguments
- allows for varying results based on arguments that will get passed later on
- reusable behavior
What two effects does a return statement have on the behavior of a function?
- causes function to produce a value that can be used in programming
- prevents any more code in function code block from being run
Why do we log things to the console?
debugging
What is a method?
- a function which is a property of an object
- in JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function
How is a method different from any other function?
methods are part of an object
How do you remove the last element from an array?
pop()
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?
strings are immutable; call a method to check the values
Roughly how many string methods are there according to the MDN Web Docs?
50+
Is the return value of a function or method useful in every situation?
no, it varies by situation
Roughly how many array methods are there according to the MDN Web docs?
50+
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators
== equal to === strict equal to != not equal to > >=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
allows for decision-making and different pathways for code
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement
if (condition) {
statement
};
What are the three logical operators?
&& logical and
|| logical or
! logical not
How do you compare two different expressions in the same condition?
(expression) && (expression)
expression) || (expression
What is the purpose of a loop?
to check a condition repeatedly until it returns false
What is the purpose of a condition expression in a loop?
tells the loop when to stop
What does “iteration” mean in the context of loops?
how ever many times the code block runs
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression for a for loop get evaluated?
once, before the loop begins
When does the condition expression for a for loop get evaluated?
after initialization and before each loop iteration
When does the final expression of a for loop get evaluated?
after code block runs and before the condition runs again
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break keyword
What does the ++ increment operator do?
adds one, returning a value that substitutes the current value
How do you iterate through the keys of an object?
using for…in loop
Why do we log things to the console?
to look at the outputs we’re working with and to also debug when a problem occurs
What is a “model?”
a replica of something