JavaScript Flashcards
What is the purpose of variables
Used to store (remember) data; short-term memory
How do you declare a variable?
Variable keyword and variable identifier (name)
What characters are allowed in variable names?
Numbers and letters, $, and underscores; numbers cannot be the first character
What does it mean to say that variable names are case sensitive?
Casing all needs to be the same or they are not the same
What is the purpose of a string
Store and manipulate text
What is the purpose of a number
To contain numeric data for calculations
What is the purpose of a Boolean
Represents true or false (binary values) useful for decision making
What does the = operator mean in JavaScript
Assignment operator; assigns a value to a variable
How do you update the value of a variable
Put the variable name again and using the assignment operator you just change the value
What is the difference between null and undefined
Null: represents nothing, something that doesn’t exist (intentional nothing put by the programmer)
Undefined: something isn’t there
Why is it good habit to include “labels” when you log values to the browser console
It’s more clear to see what data is being logged to the console and is a helpful debugging tool
Give five examples of JavaScript primitives
String, number, Boolean, undefined, null
What data type is returned by an arithmetic operation
Number
What is string concatenation
Two or more strings joined together to make a single string
What purpose(s) does the + plus operator serve in JavaScript
Addition or concatenation
What data type is returned by comparing two values
Boolean
What does the += “plus-equals” operator do
Addition assignment; adds a value then updates the variable
What are objects used for
Used to group together sets of variables and functions that have some relation to each other (can include functionality) to model or represent something
What are object properties
They are variables used within an object
Describe object literal notation
Curtly braces: sets of key-value pairs (property or method and it’s value separated by a colon) and the key-value pairs which are separated by commas except for the last one
How do you remove a property from an object
Delete keyword followed by name of the object, member operator (.), and name of property or method you want to delete
What are two ways to get or update the value of a property
Dot notation: object.property/method
Bracket notation: object[property/method]
What are arrays used for
Storing lists of values related to each other
Describe array literal notation
Data separated by commas within square brackets
How are arrays different from plain objects
Arrays have an order and their values are paired with their index (numeric index)
Objects have set properties (alpha-numeric indices) and are just collections of data with no set order
What number represents the first index of an array
0
What is the length property of an array
Array.length
Amount of items in an array
How do you calculate the last index of an array
Array.length - 1
What is a function in Javascript
A repeatable block of code designed to perform a specific task when it is invoked
Describe the parts of a function definition
Function keyword, optional function name, comma-separated parameter list of 0 or more parameters, open curly brace for the code block, optional return statement (return keyword followed by optional value), closing curly brace
When comparing them side-by-side, what are the differences between a function call and a function definition
The function call does not have the function keyword or code block within the curly braces
What is the difference between a parameter and an argument
Parameters are placeholders are variables that we declare in the function definition and that have an unknown value until we call the function and pass in the argument(a)
Arguments are actual values that we pass in when calling the function
Why are function parameters useful?
Allows the function to be reusable
Why do we log things to the console?
to see what our code is doing, if our code is functioning properly, debugging tool
What is a method?
a function which is a property of an object
How is a method different from any other function?
methods are attached to objects; you need to say specifically where the method is coming from
How do you remove the last element from an array?
.pop() method
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.random()
gives you a decimal between 0 and 1 not including 1
How do you delete an element from an array?
.splice(index, #to delete, optional replacement)
How do you append an element to an array?
.push() and .unshift()
How do you break a string up into an array?
.split(separator)
Do string methods change the original string? How would you check if you weren’t sure?
no, because strings are immutable, but you can use the console log to check
Roughly how many string methods are there according to the MDN Web docs?
~35
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
~37
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.
> < == === >= <= !== !===
What data type do comparison expressions evaluate to?
booleans
What is the purpose of an if statement?
to make decisions, to tell the code what to do in certain situations
Is else required in order to use an if statement?
nope
Describe the syntax (structure) of an if statement.
if (condition) {
code block;
}