JavaScript Flashcards
What is the purpose of variables?
To store information to be accessed later on.
How do you declare a variable?
By using var , let, or const followed by the name of the variable.
How do you initialize (assign a value to) a variable?
By declaring a variable and then using the equal sign.
What characters are allowed in variable names?
letters, numbers, dollar signs
What does it mean to say that variable names are “case sensitive”?
it means A and a are different
What is the purpose of a string?
The purpose of a string is to work with text and can contain HTML markup.
What is the purpose of a number?
To have a value that can be calculated. But also to determine screen sizes or an amount of time for an element to do something.
What is the purpose of a boolean?
To help determine when someone needs to happen or not. 1 or 0.
What does the = operator mean in JavaScript?
The equal sign operator means assign.
How do you update the value of a variable?
You would simply type the variable again without the var and assign a new value to it.
What is the difference between null and undefined?
Null is developer intended, while undefined is unintended.
Why is it a good habit to include “labels” when you log values to the browser console?
There will be many logs when the codes get more in depth and things can get confusing. Simply, its for readability.
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
A numerical value
What is string concatenation?
It’s when a string is added to another string or the value of a variable.
What purpose(s) does the + plus operator serve in JavaScript?
concatenation
What data type is returned by comparing two values (greater than, less than, ===, etc)?
Operands are being compared
What does the += “plus-equals” operator do?
It is the addition assignment. It adds the current value of something to the variable or number and the result of that expression is updated to the given variable.
What are objects used for?
Objects group together a set of variables and functions to create a model.
What are object properties?
Object properties are essentially variables.
Describe object literal notation.
An object literal notation contains an opening curly brace that holds key value pairs, followed by a closing curly brace.
How do you remove a property from an object?
By using the delete operator followed by the object name and the property name.
What are the two ways to get or update the value of a property?
By typing the object name followed by the member operator (.) followed by the assignment operator (=), followed by the new property value.
By typing the object name followed by the property name inside the square brackets followed by the equal sign and the new property value.
What are arrays used for?
Arrays are used to hold things like a shopping list or something that are closely related that can be referenced by index numbers.
Describe array literal notation.
An array notion has an opening square bracket followed by the a list of strings separated by commas and then closed off with a closing square bracket.
How are arrays different from “plain” objects?
Arrays can be accessed by index numbers while objects require dot notations.
What number represents the first index of an array?
0 zero
What is the length property of an array?
The length property would just be array.length.
How do you calculate the last index of an array?
The last index of an array is array.length - 1.
What is a function in JavaScript?
A tool in javascript to write scripts that can be reused as many times as needed.
Describe the parts of a function definition.
A function definition has a function keyword and name that can be anonymous or named, followed by parenthesis for the parameters, followed by a curly brace for the code block that has code inside to execute the given function when called.
Describe the parts of a function call.
Function call executes the function that is previously defined. It would be the name of the function along with the parenthesis.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition has a code block that can be used over and over. While calling a function would execute the definition.
What is the difference between a parameter and an argument?
A parameter is used when defining a function, while an argument is used when calling a function.
Why are function parameters useful?
Parameters are placeholders for the arguments so the function would be dynamic (reusable), instead of it being hard coded.
What two effects does a return statement have on the behavior of a function?
Return allows the function to produce a value and also prevents more code from being run.
Why do we log things to the console?
To check what the line of code is doing so we can see if it’s correct.
What is a method?
Method is a function which is a property of an object. Methods are built-in for javascript and usually have a purposeful return value.
How is a method different from any other function?
Methods are already built-in to the language. Other functions, we would need to define it.
How do you remove the last element from an array?
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?
Array.splice()
How do you append an element to an array?
Array.push(), Array.unshift(),
How do you break a string up into an array?
String.split()
Do string methods change the original string? How would you check if you weren’t sure?
You can log out the new variable if the string method was assigned.