JavaScript Flashcards
all algorithm are made with 3 parts, what are they?
variable, conditionals, and loops. how to save, decide, and repeat.
What is a script?
is a series of instructions a computer can follow step-by-step
how should you start writing a script?
start with the big picture of what you want to achieve and break down into smaller steps.
- define the goal
- design the script
- code each step
what are 2 ways to design a script
p. 18
1. tasks (flowchart)
2. steps (list)
flowchart keys
generic step (rectangle)
event (hexogon 6 sides)
input or output (slanted rectangle)
decision (diamond)
What is the purpose of variables?
to store values. easier to call upon the information and easier to reuse for future.
How do you declare a variable?
variable-keyword variable-name;
var name;
How do you initialize (assign a value to) a variable?
variable-keyword variable-name = value; var word = "word";
What characters are allowed in variable names?
lower and capital letters, $, _, and numbers, but cannot start.
var is what scope variable keyword
function scope
what is let and const variable keyword function
block scope
What does it mean to say that variable names are “case sensitive”?
score and Score are different
What is the purpose of a string?
for text
What is the purpose of a number?
to calculate and measure stuff, financial stuff.
What is the purpose of a boolean?
for decision making
What does the = operator mean in JavaScript?
assignment operator, it assigns/store the value to the variable. value will correlate with the variable.
What does the = operator mean in JavaScript?
assignment operator, it assigns the value to the variable
How do you update the value of a variable?
with an assignment operator, no need for keyword. variable = value
name = “yay”;
What is the difference between null and undefined?
undefined is never assigned by a user/programmer, it is a result that only the browser/javascript will give.
null is a value and is assigned and meant to on purpose.
Why is it a good habit to include “labels” when you log values to the browser console?
to see what that console log is for and easier to read/know when coming back to it later. makes it clear.
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined.
example of uniary operator
typeof
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adding 2 or more strings to make it into one string
What purpose(s) does the + plus operator serve in JavaScript?
it can add 2 numbers, can add two strings into one
What data type is returned by comparing two values ( less than, greater than, ===, etc)?
boolean
What does the += “plus-equals” operator do?
shorthand for adding the variable with an additional value and the result of that get the new value for the variable.
What are objects used for?
to group together a set of variable and functions to create a model of something that are related.
What are object properties?
they are variable. properties tells us about the object
Describe object literal notation.
it is to create an object. object is in curly braces and the object gets stored in a variable
keyword-variable variable = {
property: key value,
property: key value,
method: key(function-name) value(function)
};
*in object, functions are known as methods
variables are known as property
How do you remove a property from an object?
with delete operator
delete object.property
What are the two ways to get or update the value of a property?
with a dot notation or the bracket notation
how do you read vehicle[‘color’]?
vehicle at string color
[] usually read as at
what is delete?
delete operator
Ex. delete pet.name . delete operator is being used on name property of pet object.
What are arrays used for?
used when working with a list or a set of values that are related to each other. full view of that category
Describe array literal notation.
with an open bracket and closing bracket [ ]
How are arrays different from “plain” objects?
array: number index, know how many data there are, can add data by using method, numerical order
object: property names, cannot know how many property/method there are, can add by using assignment operator, not a numerical order
What number represents the first index of an array?
[0]
What is the length property of an array?
it gives the result of how many values are in an array.
How do you calculate the last index of an array?
length - 1
What is a function in JavaScript?
reusable tool that give directions on what to do/process
Describe the parts of a function definition.
function keyword with the function name(optional) parameters list(s) (optional) opening a function code block { what to process or the optional return statment closing a function code block }
Describe the parts of a function call.
the function’s name with the arguments(optional if more than one-separated with commas)
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call needs only the funtion name and parentheses, arguments are optional. function definition is basically structuring the function so that it can be used when called. it has what is to be processed once called.
What is the difference between a parameter and an argument?
arguments are the data we are asking to use as an input from a function call.
parameters are the data that is unknown until the function is called with arguments. we take to use it inside the function: a placeholder.
Why are function parameters useful?
it can take on the values of the arguments that were passed to be used in the function. ability to have utibility. provides a functionality of same process but with different data.
What two effects does a return statement have on the behavior of a function?
it will exit the function, codes after the return statment will not executed.
it will produce a value in place of the function call.
What is the purpose of a loop?
to have a condition of iterate trough a number of times. to repeat functionality
What is the purpose of a condition expression in a loop?
to make a stop condition
What does “iteration” mean in the context of loops?
number of time it repeats the code block
When does the condition expression of a while loop get evaluated?
in the beginning, before it executes the while loop code block.
When does the initialization expression of a for loop get evaluated?
only once in the beggining before executing the for loop code block
When does the condition expression of a for loop get evaluated?
on the first time, it will execute after the initialization and, everytime before it executes the code block, but after the final expression on every iteration
When does the final expression of a for loop get evaluated?
before the condition and after the code block
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
What does the ++ increment operator do?
it increaments a number by one
How do you iterate through the keys of an object?
by using for…in loop
Why do we log things to the console?
to make sure it does what you are expecting to do. To keep track and know what the ouput is coming out as expected.
What is a “model”?
representation of something
Which “document” is being referred to in the phrase Document Object Model?
html document
What is the word “object” referring to in the phrase Document Object Model?
list of properties and values.
DOM
Document Object Model, javascript object that is modeling html document contents
What is a DOM Tree?
collection of all the information that conveys one content, children, text content, elements,
Give two examples of document methods that retrieve a single element from the DOM.
getElementById, querySelector
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll, getElementsByClassName, getElementsByTagName
Why might you want to assign the return value of a DOM query to a variable?
easier to access or to call
What console method allows you to inspect the properties of a DOM element object?
dir method. console.dir
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
because the document flow, the load order, it will load from top to bottom. it will not have the info to load if script is above since it didn’t load all the body.
What does document.querySelector() take as its argument and what does it return?
takes a string css select, and will return the first element from top to bot
What does document.querySelectorAll() take as its argument and what does it return?
takes the string and will return all the elements in that string, in NodeList.