JavaScript Flashcards
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
What is the purpose of variables?
Variables are used to store data for the computers to use in the future
For the future;
JAVASCRIPT-PRIMITIVES-AND-VARIABLES
How do you declare a variable?
use a keyword (var, let, const) and variable name and =
Example: var example = 100;
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;
to make decisions
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?
Update the value of a variable by assigning a new value to the variable name without the keyword
Example: 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?
Label within the console.log to know where you’re getting values from / for organization purposes
(especially when going back to the code)
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?
numeric data
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What is string concatenation?
Process of joining together two or more strings to create one new string
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS What purpose(s) does the + plus operator serve in JavaScript?
adds one value to another;
addition of numbers and concatenation of strings
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What data type is returned by comparing two values
(>, ===, < etc)?
booleans (true or false)
JAVASCRIPT-OPERATORS-AND-EXPRESSIONS
What does the += “plus-equals” operator do?
left operand = left operand + right operand
Example: 2 += 3 = 5
JAVASCRIPT-OBJECTS
What are objects used for?
objects {} are used group together a set of variables and functions to create a model / representation of something
JAVASCRIPT-OBJECTS
What are object properties?
properties tell us about the object;
the variable of an object;
Example: name, age, etc.
JAVASCRIPT-OBJECTS
Describe object literal notation.
Store object in variable, within opening and closing curly braces are properties and their values;
Example: var object = { properties: value }
JAVASCRIPT-OBJECTS
How do you remove a property from an object?
Use delete operator
Example:
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?
Array are used for storing values in a grouped list like a grocery list where orders are not essential;
JAVASCRIPT-ARRAYS
Describe array literal notation.
var array = [ ];
JAVASCRIPT-ARRAYS
How are arrays different from “plain” objects?
Objects have individual assigned properties but arrays have automatic number indexes assigned
Within array you know how many pieces of data being stored (length property)
To add data to an array, use method (push); To add data to object, use dot / bracket notation
JAVASCRIPT-ARRAYS
What number represents the first index of an array?
0 / Zero
JAVASCRIPT-ARRAYS
What is the length property of an array?
The length property is used 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
includes a set of instructions
JAVASCRIPT-FUNCTION
Describe the parts of a function definition.
keyword, optional name, optional number of parameters, code block, 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 doesn’t have keyword function and uses ( ) to call the function
function definition has the code block and function keyword
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?
Function parameters are useful because they pass information to a function in order to be able to reuse the function code block
Without parameters, function always does the same thing
With parameters, we can input different values and get different results
JAVASCRIPT-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.
1. Will replace the function called in that line of code; Example: 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( )
pop method
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( )
0 < 1
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( )
Push method
JAVASCRIPT-METHODS
How do you break a string up into an array?
split(‘ ‘)
Split method
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?
About 50
JAVASCRIPT-METHODS
Is the return value of a function or method useful in every situation?
No, not in every situation
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
which stands for: Mozilla Developer Network
JAVASCRIPT-IF
Give 6 examples of comparison operators.
== is equal to; != is not equal to; === is strictly equal to; !== is strictly not equal to; > is greater than; < is less than; >= is greater than or equal to; <= is less than or equal to;
JAVASCRIPT-IF
What data type do comparison expressions evaluate to?
Boolean (true or false)
JAVASCRIPT-IF
What is the purpose of an if statement?
An if statement evaluates (or checks) a condition.
Let the computer make a decision based on conditions.
JAVASCRIPT-IF
Is else required in order to use an if statement?
no, only if you want to provide more than one set of code / another execution
JAVASCRIPT-IF
Describe the syntax (structure) of an if statement.
if (condition)… conditional code block
instruction: { } else { }
JAVASCRIPT-IF
What are the three logical operators?
&& (and) ;
|| (or);
! (not);
JAVASCRIPT-IF
How do you compare two different expressions in the same condition?
&& (and);
|| (or);
JAVASCRIPT-LOOPS
What is the purpose of a loop?
To continuously iterate through a code block until the condition is met
Allows us to repeat a certain function
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
Before condition runs again
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