JavaScript Flashcards
What is the purpose of variables?
Store information for the script to its job.
How do you declare a variable?
First use the variable keyword, then the variable name.
How do you initialize (assign a value to) a variable?
After the variable name use the equal sign or assignment operator then the variable value.
What characters are allowed in variable names?
letters, underscore, dollar sign, numbers.
What does it mean to say that variable names are “case sensitive”?
The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
What is the purpose of a string?
Working with any kind of text. Represent and manipulate a sequence of characters.
What is the purpose of a number?
Working with numeric data.
What is the purpose of a boolean?
Create true or false statements. Determine which part of a script should run.
What does the = operator mean in JavaScript?
Is an assignment operator. Is used to give the value to a variable.
How do you update the value of a variable?
Just use the variable name, the equals sign and the new value.
What is the difference between null and undefined?
Undefinided is a variable has been declared but has not been assigned a value. Null is an assignment value. It can be assigned to a variable as a representation of no value.
Why is it a good habit to include “labels” when you log values to the browser console?
Is good to avoid confusions between similar values.
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined.
What data type is returned by an arithmetic operation?
Numerical value.
What purpose(s) does the + plus operator serve in JavaScript?
The addition operator ( + ) produces the sum of numeric operands or string concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
A boolean value (true or false).
What does the += “plus-equals” operator do?
The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable.
What is string concatenation?
Join two or more strings values into one value.
What are object properties?
An association between a name (or key) and a value
Describe object literal notation.
Value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last one
How do you remove a property from an object?
Using the delete operator.
What are the two ways to get or update the value of a property?
With a dot and with brackets.
What are objects used for?
For store data as properties (key-value pairs).
What are arrays used for?
Used to store values that are related to each other.
Describe array literal notation.
a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ( [] )
What number represents the first index of an array?
zero.
What is the length property of an array?
size of the array or the total number of elements present in the array.
How do you calculate the last index of an array?
Get the last element of ArrayList with use of get(index) method by passing index = size – 1.
How are arrays different from “plain” objects?
Arrays are used when we store multiple values of a single variable, while an object can contain multiple variables or properties with their values.
What is a function in JavaScript?
A JavaScript function is a block of code designed to perform a particular task.
Describe the parts of a function definition.
- Function keyword
- Optional name.
- Parameters separated by a comma.
- Opening curly brace { for the code block.
- Optional return.
- -Closing curly brace} for the code block
Describe the parts of a function call.
The function’s name. A comma separated the arguments surrounded by parentheses.
When comparing them side-by-side, what are the differences between a function call and a function definition?
Define a function doesn’t cause the code block run because is just an object. Call an object does the code block run.
What is the difference between a parameter and an argument?
parameters are the name within the function definition.
Arguments are the values passed in 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 in our program
- Used to stop the function.
Why are function parameters useful?
They received the arguments that are passed when the function is called.
What are the four components of “the Cascade”.
- Source order
- Inheritance
- Specificity
- !important
Why do we log things to the console?
to verify that what we are doing is correct
What is a method?
Is statement or code block that performs a specific task.
How is a method different from any other function?
Method is function that belongs to an object while function not.
How do you remove the last element from an array?
With pop method
How do you round a number down to the nearest integer?
Math.floor method
How do you generate a random number?
Random method
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, we can console.log the original variable
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.
strictly equal(===), not equal to (!=), not strict equal to(!==), greater than (>), less than(<), greater or equal than (>=), less or equal than (<=).
What data type do comparison expressions evaluate to?
Boolean values
Is else required in order to use an if statement?
No
What are the three logical operators?
logical and(&&), logical or (| |), logical not (!)
Syntax of an if statement
if keyword, condition, opening curly brace, code to execute if value is true, closing curly bracket
What is the purpose of a loop?
repeat the same, or similar, code a number of times. Simplify work.
What is the purpose of a condition expression in a loop?
tested each time the loop repeats.
What does “iteration” mean in the context of loops?
sequence of instructions that is continually repeated.
When does the condition expression of a while loop get evaluated?
An expression evaluated before each pass through the loop.
When does the initialization expression of a for loop get evaluated?
before the execution of the first loop.
When does the condition expression of a for loop get evaluated?
each time before the loop runs.
When does the final expression of a for loop get evaluated?
This expression is executed after each iteration of the loop
which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break keyword
What does the ++ increment operator do?
increases the value of a variable by 1
How do you iterate through the keys of an object?
With for..in loops.
Why do we log things to the console?
Test if what we did works before to print the final result to the user.
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?
Represent each object that conform the structure and content of a document on the web.
What is a DOM Tree?
Structure of nested nodes.
Give two examples of document methods that retrieve a single element from the DOM.
querySelector() and getElementById()
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementsByClassName()
Why might you want to assign the return value of a DOM query to a variable?
If you want to work with that element more than once
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
Because the browser needs to parse all of the elements in the HTML page before JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
Takes a string that contains css selector describing the HTML element you want to work with. Returns only the first of the matching elements
What does document.querySelectorAll() take as its argument and what does it return?
Takes a css selector and returns all of those that match.