JavaScript Flashcards
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of variables?
to store data for the computers to use in the future
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you declare a variable?
use a keyword (var, let, const) and variable name and =
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you initialize (assign a value to) a variable?
use an equal sign
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What characters are allowed in variable names?
letter, numbers, $, underscore,
numbers cant be first
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What does it mean to say that variable names are “case sensitive”?
Car= and car= are different variables
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of a string?
for storing text that wouldn’t make sense to JavaScript
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of a number?
for doing calculations
if the number is a zipcode then store as string
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of a boolean?
it is for letting computers make a decision that is true or false
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What does the = operator mean in JavaScript?
assignment operator
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you update the value of a variable?
by assigning a new value to the variable name without the keyword.
let a = 2; for declaring a variable a = 5; for updating a variable (no need for keyword)
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the difference between null and undefined?
- null is absents of value intentionally (ex: optional user input)
- undefined is not trustworthy
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
Why is it a good habit to include “labels” when you log values to the browser console?
to know where you’re getting values from. for organization purposes
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
Give five examples of JavaScript primitives.
string, number, boolean, null, and undefined
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What data type is returned by an arithmetic operation?
a number data
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What is string concatenation?
glueing strings together
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What purpose(s) does the + plus operator serve in JavaScript?
addition of numbers and concatination if strings
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What data type is returned by comparing two values (, ===, etc)?
booleans
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What does the += “plus-equals” operator do?
left operand = left operand + right operand
JAVASCRIPT-OBJECTS
What are objects used for?
to group together data that can represent something
JAVASCRIPT-OBJECTS
What are object properties?
variables that is glued to an object
JAVASCRIPT-OBJECTS
Describe object literal notation.
var obj = { properties: value }
JAVASCRIPT-OBJECTS
How do you remove a property from an object?
use the delete as ex: delete object.property or delete object[‘property’]
JAVASCRIPT-OBJECTS
What are the two ways to get or update the value of a property?
dot notation or bracket notation
JAVASCRIPT-ARRAYS
What are arrays used for?
storing values in a grouped list like a grocery list where orders are not essential
JAVASCRIPT-ARRAYS
Describe array literal notation.
var variable = [ ]
JAVASCRIPT-ARRAYS
How are arrays different from “plain” objects?
objects have individual assigned properties but arrays have automatic number indexes assigned
JAVASCRIPT-ARRAYS
What number represents the first index of an array?
0
JAVASCRIPT-ARRAYS
What is the length property of an array?
to find the length of an array
JAVASCRIPT-ARRAYS
How do you calculate the last index of an array?
array.length - 1
JAVASCRIPT-FUNCTION
What is a function in JavaScript?
a reusable block of code
JAVASCRIPT-FUNCTION
Describe the parts of a function definition.
keyword, optional name, optional number of parameters, code, return
JAVASCRIPT-FUNCTION
Describe the parts of a function call.
name, ( ) and arguments
JAVASCRIPT-FUNCTION
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call doesnt have keyword function and uses ( ) to call the function
JAVASCRIPT-FUNCTION
What is the difference between a parameter and an argument?
parameter = placeholder for potential value argument = actual value being placed in the argument
JAVASCRIPT-FUNCTION
Why are function parameters useful?
pass information to a function, to be able to reuse the function code block
JAVASCRIPT-FUNCTION
What two effects does a return statement have on the behavior of a function?
1. will replace the function called in that line of code. ex: function(3) = 10 var x = function(3) will become var x = 10
- stops the function entirely once a value is returned
JAVASCRIPT-METHODS
Why do we log things to the console?
to debug our code, to check if our output is as expected, etc
JAVASCRIPT-METHODS
What is a method?
function that is a property of an object
JAVASCRIPT-METHODS
How is a method different from any other function?
methods have to be called on an object, functions do not
JAVASCRIPT-METHODS
How do you remove the last element from an array?
pop( )
JAVASCRIPT-METHODS
How do you round a number down to the nearest integer?
Math.floor( )
JAVASCRIPT-METHODS
How do you generate a random number?
Math.random( )
JAVASCRIPT-METHODS
How do you delete an element from an array?
pop for last item, shift for first item, splice for specific index
JAVASCRIPT-METHODS
How do you append (to the end) an element to an array?
push
JAVASCRIPT-METHODS
How do you break a string up into an array?
split(‘ ‘)
JAVASCRIPT-METHODS
Do string methods change the original string? How would you check if you weren’t sure?
does not change the original string. to check: console.log( )
JAVASCRIPT-METHODS
Roughly how many string methods are there according to the MDN Web docs?
like 50
JAVASCRIPT-METHODS
Is the return value of a function or method useful in every situation?
no
JAVASCRIPT-METHODS
Roughly how many array methods are there according to the MDN Web docs?
a lot
JAVASCRIPT-METHODS
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
JAVASCRIPT-IF
Give 6 examples of comparison operators.
greater than equal, greater than, less than equal, less than, ==, ===
JAVASCRIPT-IF
What data type do comparison expressions evaluate to?
boolean, true or false
JAVASCRIPT-IF
What is the purpose of an if statement?
to let the computer make a decision based on conditions
JAVASCRIPT-IF
Is else required in order to use an if statement?
no
JAVASCRIPT-IF
Describe the syntax (structure) of an if statement.
if (conditions) { } else { }
JAVASCRIPT-IF
What are the three logical operators?
&& and || and !
JAVASCRIPT-IF
How do you compare two different expressions in the same condition?
&& or ||
JAVASCRIPT-LOOPS
What is the purpose of a loop?
to continuously iterate through a code block until the condition is met
JAVASCRIPT-LOOPS
What is the purpose of a condition expression in a loop?
to know when to stop the loop
JAVASCRIPT-LOOPS
What does “iteration” mean in the context of loops?
iteration = looping through once
JAVASCRIPT-LOOPS
When does the condition expression of a while loop get evaluated?
at the start of every loop
JAVASCRIPT-LOOPS
When does the initialization expression of a for loop get evaluated?
before the loop begins and only once
JAVASCRIPT-LOOPS
When does the condition expression of a for loop get evaluated?
before each iteration
JAVASCRIPT-LOOPS
When does the final expression of a for loop get evaluated?
after each iteration
JAVASCRIPT-LOOPS
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
JAVASCRIPT-LOOPS
What does the ++ increment operator do?
increments by 1
JAVASCRIPT-LOOPS
How do you iterate through the keys of an object?
for in loop
DOM-QUERYING
Why do we log things to the console?
to see what we’re doing and for debugging
DOM-QUERYING
What is a “model”?
a representation of something
DOM-QUERYING
Which “document” is being referred to in the phrase Document Object Model?
the html document