JavaScript (Junior Side) Flashcards
What is the purpose of variables?
they are a way to store information so that we can come back to it later.
What is the purpose of a boolean?
To make logical decisions.
How do youdeclarea variable?
by using var, const, or let
How do you initialize (assign a value to) a variable?
By using the assignment operator ( = )
What characters are allowed in variable names?
letter, number, or dollar sign $
What does it mean to say that variable names are “case sensitive”?
capitalized and lowercase letters, even if they are the same letter, will have two different values if assigned to a variable
What is the purpose of a string?
For storing a sequence of characters that javScript will not try to interpret / creating “text”
What is the purpose of a number?
For numbers that may / will be used in mathematical operations
How do you update the value of a variable?
put the name of the variable with an assignment operator and a new value.
Do not use the “var, let, or const” keywords, because the variable has already been declared.
What does the=operator mean in JavaScript?
assigns the value of its right operand to its left operand.
What is the difference betweennullandundefined?
Null is an intentional assignment of no value.
Undefined is an empty value that JS is ‘free to use’
Why is it a good habit to include “labels” when you log values to the browser console?
For clarity when coming back to reference code at a later time.
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?
adding strings together to make a new string
Does concat change the original string?
No, it makes new strings that consist of the previous strings
What purpose(s) does the+plus operator serve in JavaScript?
math or concatenation
What data type is returned by comparing two values (<,>,===, etc)?
boolean
What does the+=”plus-equals” operator do?
makes a lasting change / adds and assigns
What are objects used for?
a way to group together sets of data that are related to each other
What are object properties?
variables inside of an object
Describe object literal notation.
curly brace, then a property, the a colon, then a comma, then the next property declaration, etc., ended by a closing curly brace
How do you remove a property from an object?
use 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?
for storing a sequence of related information for use at a later time
describe array literal notation
[ ‘word’, ‘word2’ ]
how are arrays different from “plain” objects?
arrays are indexed/ have an order, objects are not
what number represents the first index of an array?
0
what is the length property of an array?
arrayName.length, a true count of items that are indexed in the array
how do we calculate last index of an array?
array.length -1
What is a function in JavaScript?
Functions allow you to package up code for use later in your program.
Describe the parts of a function definition.
function keyword
optional name
parameters (separated , by , commas)
start of the code block ( { ) with a return…maybe
optional return statement
close of the code block (})
Describe the parts of a function call.
function name
( ) parenthesis
arguments list
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call just has the name and arguments
function definition has name, parameters, { } , and code block
What is the difference between a parameter and an argument?
when we define a function, we declare parameters and that when we call a function, we pass it arguments
parameter is placeholder, argument is the actual value
Why are function parameters useful?
They give us more control over the function
What two effects does a return statement have on the behavior of a function?
- Causes the function to produce a value we can use in our program.
- Prevents any more code in the function’s code block from being run.
What is a method?
A method is a function which is a property of an object.
why do we log things to the console?
its a debugging tool
What is a method?
a function stored in the property of an object
How is a method different from any other function?
Methods must be attached to an object, functions do not
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( ) method
floor method of the math object
How do you generate a random number?
Math.random( )
random method of the math object
0 0.999
How do you delete an element from an array?
.splice( ) method
How do you append an element to an array?
.push ( ) method
How do you break a string up into an array?
.split ( ) method
Do string methods change the original string? How would you check if you weren’t sure?
No!
console.log( ) the string using a method
Roughly how many string methods are there according to the MDN Web docs?
A LOT
Is the return value of a function or method useful in every situation?
No, example . push( ) or .pop( )
Roughly how many array methods are there according to the MDN Web docs?
A LOT
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?
booleans
What is the purpose of an if statement?
to make logical decisions in code
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if keyword, condition, code block
What are the three logical operators?
&& , ||, !
and, or, not
How do you compare two different expressions in the same condition?
With a logical operator (either && or ||)
what is the purpose of a loop?
to repeat functionality when needed
What is the purpose of a condition expression in a loop?
to determine whether or not the loop continues repeating.
if true, loop continues, if false, loop stops.
What does “iteration” mean in the context of loops?
one full time that the code block has been run.
When does the condition expression of a while loop get evaluated?
before the loop code block executes
When does the initialization expression of a for loop get evaluated?
once before anything happens
When does the condition expression of a for loop get evaluated?
before code block of next iteration, and after the final expression
When does the final expression of a for loop get evaluated?
before the condition, and after the code block runs
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break