javascripot Flashcards
What is the purpose of variables?
to store values
How do you declare a variable?
var name
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
period, undrescore, characters $#@, and letters
What does it mean to say that variable names are “case sensitive”?
a capital letter changes the variable, different variable
What is the purpose of a string?
store characters
What is the purpose of a number?
numerical value to math or store
What is the purpose of a boolean?
gives true/false values
What does the = operator mean in JavaScript?
assign value
How do you update the value of a variable?
assign a new value to the variable
What is the difference between null and undefined?
null is intentionally undefined, undefined was just never given any value
Why is it a good habit to include “labels” when you log values to the browser console?
so you know what is logging what in longer code.
Give five examples of JavaScript primitives.
undefined, null, boolean, string and number
What data type is returned by an arithmetic operation?
number
What is string concatenation?
appending a string onto another string
What purpose(s) does the + plus operator serve in JavaScript?
arithmetic addition and string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
sets the value to the value plus the number
What are objects used for?
groups set of variables and functions to create a model of something
What are object properties?
a variable that is part of an object
Describe object literal notation.
setting a var object = {}
How do you remove a property from an object?
using the delete keyword
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
set of values related to each other, a list
Describe array literal notation.
var array = []
How are arrays different from “plain” objects?
What number represents the first index of an array?
0
What is the length property of an array?
How many values are int he array
How do you calculate the last index of an array?
.lenght-1
What is a function in JavaScript?
set of code that takes arguments and can be called
Describe the parts of a function definition.
function operator-name of function(parameters) { }
Describe the parts of a function call.
function(arguments);
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition uses function keyword, calling uses the function name and arguments.
What is the difference between a parameter and an argument?
parameters are placeholders that can store arguments.
Why are function parameters useful?
Makes functions reusable with different arguments.
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.
Why do we log things to the console?
Check console output to see where we are in code and for errors
What is a method?
a function which is a property of an object
How is a method different from any other function?
it is associated with 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 or .unshift or .splice(0 placement appended)
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?
no. console.log the string before and after the method
Roughly how many string methods are there according to the MDN Web docs?
~30
Is the return value of a function or method useful in every situation?
no. push, unshift return length of array- splice returns spliced element.
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Roughly how many array methods are there according to the MDN Web docs?
~30
Give 6 examples of comparison operators.
great, less than, greater =, lesser =, equal to, not equal to, strictly equal to
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
determines execution path based on a condition
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if (condition) {
code
};
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
if else
What is the purpose of a loop?
to reiterate code during a condition
What is the purpose of a condition expression in a loop?
to tell the loop when to stop iterating
What does “iteration” mean in the context of loops?
one time through the loop
When does the condition expression of a while loop get evaluated?
at the beginning before code block runs.
When does the initialization expression of a for loop get evaluated?
at the start once before iteration
When does the condition expression of a for loop get evaluated?
after initialization and before the code runs
When does the final expression of a for loop get evaluated?
before the condition expression.
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?
adds 1
How do you iterate through the keys of an object?
for in loop
What is a method?
function which is a property of an object.
How can you tell the difference between a method definition and a method call?
call is object.methodname definition is methodname: function ()
Describe method definition syntax (structure).
var object = { methodname: function(){ } }
Describe method call syntax (structure).
object.methodname
How is a method different from any other function?
tied to an object
What is the defining characteristic of Object-Oriented Programming?
based on objects and procedures
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What does API stand for?
Application programming interface
What is the purpose of an API?
simplify for users
What is this in JavaScript?
this keyword refers to an object.
this is an implicit parameter of all JavaScript functions.
What does it mean to say that this is an “implicit parameter”?
parameter not explicitly defined
When is the value of this determined in a function; call time or definition time?
call time
What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } };
Mario
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
It’s a me Mario!
because the this.firstName calls the character object to fill the statement
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
undefined
How can you tell what the value of this will be for a particular function or method definition?
it is defined at definition
How can you tell what the value of this is for a particular function or method call?
the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method).