JavaScript Flashcards
what is the purpose of variables?
store data for reuse
how do you declare a variable?
var
how do you initialize (assign a value to) a variable?
var x = ‘string’;
what characters are allowed in variable names?
letters, numbers, $, _
however must start with letter, $, or _.
must not use - or .
what does it mean to say that variable names are “case sensitive”
the slightest capitalization difference for the same word will count as different variables
what is the purpose of string?
used when working with any kind of text
what is the purpose of a number?
for tasks that involve counting or calculating sums
what is the purpose of boolean?
helpful when determining which part of a script should run/ acts as an on or off switch
what does the = operator mean in javascript?
assignment operator
how do you update the value of a variable?
use the variable name, the equals sign, and the new value
what is the difference between null and undefined?
null represents a reference that points to a nonexistent or invalid object or address
undefined is a value assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments
why is it a good habit to include labels when you log values to the browser console?
easier to keep track of console output for yourself and others
give five examples of javascript primitives
string, number, boolean, undefined, null
what data type is returned by an arithmetic operation?
number
what is string concatenation?
placing string together to form a single output of string
what purpose(s) does the + plus operator serve in JS?
concatenation and addition
what data type is returned by comparing two values (,===, etc)?
boolean
what does the += plus-equals operator do?
adds the value of the right operand to a variable and assigns the result to the variable
what are objects used for?
objects group together a set of variables and functions to create a model of something you would recognize from the real world
what are object properties?
exclusive variables - another way to store data
describe object literal notation
assigning the object properties within { }
how do you remove a property from an object?
delete object.property
what are the two ways to get or update the value of a property
use dot or bracket notation
what are arrays used for?
when you are working with a list or a set of values that are related to each other
describe array literal notation
var colors = [ ] ;
how are arrays different from “plain” objects?
arrays use indexes to keep track of items
what number represents the first index of an array?
0
what is the length property of an array?
tells how many items are in the array
how do you calculate the last index of an array?
array.length - 1
what is a function in JavaScript?
set of statements that perform a task
describe the parts of a function definition
function keyword, optional name, parameters, code block, return statement, {}
describe the parts of a function call
function name, arguments ( )
when comparing them side-by-side, what are the differences between a function call and a function definition?
function call - actually using the function
function definition - creating the code to run
what is the difference between a parameter and an argument?
parameters are variables that doesn’t have a value yet
arguments are the user values
why are function parameters useful?
used as placeholders for when the function is called
what two effects does a return statement have on the behavior of a function?
causes the function to produce a value we can use
prevents any more code in the function’s code block from being run
why do we log things to the console?
during development, check if output matches what you are expecting
debugging
what is a method?
function which is a property 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?
they return a new string
check with MDN - documentation or try yourself on console log
roughly how many string methods are there according to the MDN web docs?
~35 remember to check MDN
is the return value of a function or method useful in every situation?
no, sometimes function/methods do not need to return a value
roughly how many array methods are there according to the MDN web docs?
~30 remember to check MDN
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
=== !== >= <= >
what data type do comparison expressions evaluate to?
boolean