JavaScript Flashcards
What is the purpose of variables?
stores data value that can be changed and used later on
How do you declare a variable?
using var keyword.
How do you initialize (assign a value to) a variable?
var keyword, variable name, assignment operator, and value.
What characters are allowed in variable names?
variable names cannot contain any spaces. Must start with a letter, underscore, or dollar sign. names can only contain letters, numbers, underscores, or dollar signs. names are case sensitive.
What does it mean to say that variable names are “case sensitive”?
means any identifier must be typed with a consistent capitalization of numbers.
What is the difference between null and undefined?
null is representation of no value, undefined means a variable has been declared but not yet has been assigned a value.
Why is it a good habit to include “labels” when you log values to the browser console?
so that you know what is being logged.
Give five examples of JavaScript primitives.
strings, numbers, null, undefined, boolean
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
joining string together.
What purpose(s) does the + plus operator serve in JavaScript?
for concatenation and adding numeric values together
What data type is returned by comparing two values (< , >, ===, etc)?
boolean value
What does the += “plus-equals” operator do?
adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
objects group together a set of variable and functions to create a model of something.
What are object properties?
a variable that is part of an object.
Describe object literal notation.
var keyword, variable name, assignment operator, key value pairs.
How do you remove a property from an object?
use delete keyword followed by the object name and property name.
What are the two ways to get or update the value of a property?
object name, dot notation, followed by property name, assignment operator and property value. object name, square bracket, property name in string assignment operator, and property value.
What are arrays used for?
a list or set of values that are related to each other. Making lists of related of the exact same type.
What number represents the first index of an array?
0.
What is the length property of an array?
gives the number of items in array.
How do you calculate the last index of an array?
array.length - 1.
Describe array literal notation.
var keyword, variable name, assignment operator, square bracket, array values.
How are arrays different from “plain” objects?
arrays keys are index, object keys are properties.
What is a function in JavaScript?
a set of statements that performs a task or calculates a value and can be reused throughout a program
Describe the parts of a function definition.
function keyword, optional function name, parameter with optional values, followed by code block for the function. optional return statement.
Describe the parts of a function call.
function name, with optional arguments.
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call does not have the function keyword. function call does not have a code block to execute.
What is the difference between a parameter and an argument?
Parameters are variables listed as a part of the function definition. Arguments are values passed to the function when it is invoked.
Why are function parameters useful?
You can think of a parameter as a placeholder. It is basically a variable whose value is not known until we call the function and pass an argument. When the function’s code block is run, the parameter will be holding the value of the argument.
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?
debugging tool used to check what your output would be.
What is a method?
A method is a function which is a property of an object.
How is a method different from any other function?
methods are always related to objects, functions are not. methods are built in, functions are not. when using a method, there will always be a dot before the method and a parenthesis after.
How do you remove the last element from an array?
pop method on the array
How do you round a number down to the nearest integer?
using floor method of math object.
How do you generate a random number?
using random method of math object.
How do you delete an element from an array?
using pop method on the array to delete last item, or using shift method on the array to delete first item. You can also use splice method on the array and specify the beginning and number of items to manually delete items in array
How do you append an element to an array?
using push method on the array
How do you break a string up into an array?
using the split method on the string.
Do string methods change the original string? How would you check if you weren’t sure?
no, you can console log the original string to see if anything changed.
Roughly how many string methods are there according to the MDN Web docs?
about 50.
Is the return value of a function or method useful in every situation?
no because when using methods, the return value may not be needed.
Roughly how many array methods are there according to the MDN Web docs?
around 35
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN