JavaScript Flashcards
What is the purpose of variables?
the ability to store data that can change every time a script runs.
How do you declare a variable?
var (keyword) varName(Variable Name/Identifier) = (Assignment Operator) number/string/boolean(Value)
How do you initialize (assign a value to) a variable?
use an equals sign(=) . aka the Assignment Operator
What characters are allowed in variable names?
letters, numbers, dollar sign($), underscore(_),
cannot start with a number.
no dash(-) or period(.) in a variable name.
no keywords or reserved words.
What does it mean to say that variable names are “case sensitive”?
an example would be that var alvaro and var Alvaro would be different variable names.
try not to create variables that have the same name doing different things.
What is the purpose of a string?
strings can be used when working with some type of text.
What is the purpose of a number?
when working with any arithmetic or something with a numeric value
What is the purpose of a boolean?
to tell whether true or false, also to tell JS which path to take.
What does the = operator mean in JavaScript?
Assignment Operator
How do you update the value of a variable?
you can use dot notation or square brackets.
What is the difference between null and undefined?
null is something you place there and undefined is placed there by the browser.
Why is it a good habit to include “labels” when you log values to the browser console?
to help clarify whats being logged when you go back and review the code.
Give five examples of JavaScript primitives.
Numeric value, String, Boolean value, null, and undefined.
What data type is returned by an arithmetic operation?
always a numeric value.
What is string concatenation?
connecting two different strings or data that you want to be together.
What purpose(s) does the + plus operator serve in JavaScript?
its the addition operator, as well the concatenation operator.
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean value (true or false).
What does the += “plus-equals” operator do?
the addition assignment operator adds the value of the right side(right operand) and assigns the result to the variable.
What are arrays used for?
to store a list of related values.
Describe array literal notation.
var example = [‘one’, ‘two’, ‘three’];
How are arrays different from “plain” objects?
arrays are indexed such as 0, 1, 2, 3
objects cant use .length property.
What number represents the first index of an array?
0
What is the length property of an array?
length property tells you how many items are in the array.
How do you calculate the last index of an array?
var lastIndex = arrayName.length;
use dot notation = .length
Why do we log things to the console?
to be able to check the output and see if our code is working how it should.
What is a method?
A method is a function which is a property of an object.
instance methods
static methods
How is a method different from any other function?
a method needs to be attached to an object.
How do you remove the last element from an array?
pop( )
How do you round a number down to the nearest integer?
Math.floor( )
How do you generate a random number?
Math.random( )
How do you delete an element from an array?
.splice( )
How do you append an element to an array?
.push( )
How do you break a string up into an array?
.split( )
Do string methods change the original string? How would you check if you weren’t sure?
string methods do not change original string.
console.log the string
Is the return value of a function or method useful in every situation?
not necessarily if the function or method is coded correctly you dont really need it.
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
What is the purpose of a loop?
Loops check a condition, if the condition returns true the code block will run again, it repeats until condition returns false.
Loops offer a quick way to do something repeatedly. without writing something over and over.
What is the purpose of a condition expression in a loop?
the condition is checked before a loop runs, if the condition is true the code will run until the condition is false.
What does “iteration” mean in the context of loops?
each time the computer runs through a loop its considered an iteration.
When does the condition expression of a while loop get evaluated?
The condition is evaluated before executing the code block.
before every iteration.
When does the initialization expression of a for loop get evaluated?
the initialization gets evaluated once before the loop begins.
When does the condition expression of a for loop get evaluated?
condition expression gets evaluated before each loop iteration, if evaluates to true, statement is executed, if evaluates to false it exits the loop and goes to the first statement after the for { } construct
When does the final expression of a for loop get evaluated?
Final expression to be evaluated at the end of each loop iteration. generally used to update or increment the variable.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break statement terminates the current loop.
What does the ++ increment operator do?
The increment operator (++) increments (adds one to) its operand and returns a value.
How do you iterate through the keys of an object?
for in loop - iterates over all enumerable properties of an object that are keyed by strings (ignoring ones keyed by Symbols), including inherited enumerable properties.
Why do we log things to the console?
to be able to see what our code is actually doing and make sure its doing what its supposed to.
What is a “model”?
as the browser loads the webpage it creates a model, that model is called the DOM Tree, it i s stored in the browsers memory, and consists of four main types of nodes.
- The Document Node
- Element Nodes
- Attribute Nodes
- Text Nodes.
Which “document” is being referred to in the phrase Document Object Model?
the html document or the whole webpage.