JavaScript Flashcards
What is the purpose of variables?
store and manipulate data in the future
How do you declare a variable?
var, const, or let
How do you initialize (assign a value to) a variable?
use = (assignment operator) after declaring the variable
What characters are allowed in variable names?
letters, dollar sign, underscore, numbers (not first character)
What does it mean to say that variable names are “case sensitive”?
uppercase and lowercase letters are considered different by the engine
What is the purpose of a string?
store/manipulate text content
What is the purpose of a number?
store/manipulate numbers with math
What is the purpose of a boolean?
logic with binary states, decision making
What does the = operator mean in JavaScript?
assignment operator
How do you update the value of a variable?
use assignment operator (variable = value)
What is the difference between null and undefined?
null is intentional emptiness (can’t exist unless assigned to variable), undefined is default value of variables
Why is it a good habit to include “labels” when you log values to the browser console?
understand what the log’s content contains
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
attach one string to another to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
arithmetic addition, string concatenation if string is present
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
add/concatenate a value onto stated variable, then assign the result to the variable
What are objects used for?
storing related data within a single variable
What are object properties?
the “variables” contained within the object, key and value pair
Describe object literal notation.
curly braces containing properties, property : value
How do you remove a property from an object?
using the “delete” operator
What are the two ways to get or update the value of a property?
dot notation ( object.property ) / bracket notation ( object[‘property’] )
What are arrays used for?
storing related values within a single variable
Describe array literal notation.
values in brackets, separated by commas
How are arrays different from “plain” objects?
there is no “key”, but rather an index for each value. it’s an ordered list.
What number represents the first index of an array?
0
What is the length property of an array?
the amount of values in the array
How do you calculate the last index of an array?
array length - 1
• What is a function in JavaScript?
○ A set of code that can be called in the future with arguments that can affect the outcome of the code.
• Describe the parts of a function definition.
○ keyword, name, parameters, code block
• Describe the parts of a function call.
○ name, arguments
• When comparing them side-by-side, what are the differences between a function call and a function definition?
○ function definition has a code block, keyword, and parameters rather than arguments
• What is the difference between a parameter and an argument?
○ parameter is a placeholder, argument is the data sent to function
• Why are function parameters useful?
○ placeholder. allows data to influence the return
• What two effects does a return statement have on the behavior of a function?
○ exits and gets back the value
Why do we log things to the console?
Development debugging tool
What is a method?
A function defined as a property within an object
How is a method different from any other function?
not much, just in an object
How do you remove the last element from an array?
array.pop
How do you round a number down to the nearest integer?
Math.round(x)
How do you generate a random number?
Math.random() (gives a percentage value)
How do you delete an element from an array (at any index)?
array.splice
How do you append an element to an array?
array.push
How do you break a string up into an array?
string.split(seperator as string)
Do string methods change the original string? How would you check if you weren’t sure?
they don’t. check via console log
Is the return value of a function or method useful in every situation?
no
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, strictly equal, not equal, strictly not equal, greater, greater and equal, less than, less than and equal
• What data type do comparison expressions evaluate to?
○ boolean
• What is the purpose of an if statement?
○ to allow for decision based on whether or not something is true or false
• Is else required in order to use an if statement?
○ no
• Describe the syntax (structure) of an if statement.
• Describe the syntax (structure) of an if statement.
• What are the three logical operators?
○ AND &&, OR ||, NOT !
• How do you compare two different expressions in the same condition?
○ use logic operators
• What is the purpose of a loop
○ to allow for repeated tasks
• What is the purpose of a condition expression in a loop?
○ determine whether to continue the loop
• What does “iteration” mean in the context of loops?
○ a single cycle of a loop
• When does the condition expression of a while loop get evaluated?
○ before the code block
• When does the initialization expression of a for loop get evaluated?
○ before the first condition, at the beginning ONCE