Javascript Flashcards
What is the purpose of variables?
It allows you to store data
How do youdeclarea variable?
var keyword with the variable name
How do you initialize (assign a value to) a variable?
use the assignment operator ( = )
What characters are allowed in variable names?
Can start with $, _, or any letter
Cannot start with a number
Cannot use - or .
Cannot use keywords like var
What does it mean to say that variable names are “case sensitive”?
happy and hAppy will be two different variables
What is the purpose of a string?
To provide data as text
What is the purpose of a number?
To provide numeric value for a variable or for calculations
What is the purpose of a boolean?
Give a true or false value
What does the=operator mean in JavaScript?
Assigns a value
How do you update the value of a variable?
you can assign the variable to a new value
What is the difference betweennullandundefined?
Null is intentionally left empty, Undefined is a variable with no value
var apple;
VS.
var apple = undefined;
Why is it a good habit to include “labels” when you log values to the browser console?
It allows you to see if you code is working properly and provides clarity
Give five examples of JavaScript primitives.
Number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Joining of strings using + operator
What purpose(s) does the+plus operator serve in JavaScript?
Addition or concatenation
Adds one value to anoter
What data type is returned by comparing two values (,===, etc)?
Boolean
What does the+=”plus-equals” operator do?
It adds the value on the right side of the operator to the value of the variable on the left side and reassigns it to the variable on the left side
Var motto = fullName + ‘ is the GOAT’
Motto += ‘ is the GOAT’
What are objects used for?
Storing multiple functions or properties of an item
What are object properties?
key value pairs relating to the defined variable
Describe object literal notation.
A variable is defined
There is the opening curling brace for the code block
Properties made of key value pairs separated by commas
closing curly brace of the code block
Semicolon
How do you remove a property from an object?
delete variable.property
What are the two ways to get or update the value of a property?
Reassign the value of the variable
Create a var.property and have a value assigned to it
What are arrays used for?
It stores a list of values that are related to each other
Describe array literal notation
Var is defined
opening brace for the code block
string, numbers, or booleans separated by commas
closing brace for the code block
semicolon
How are arrays different from “plain” objects?
Instead of properties with their own unique key value pairs, the key for each value in an array is represented by its index number
What number represents the first index of an array?
0
What is thelengthproperty of an array?
The number of items in the array
How do you calculate the last index of an array?
Array[Array.length - 1]
What are objects used for?
Storing multiple functions or attributes of an item
What are object properties?
Key value pairs
Describe object literal notation.
A variable being defined
Start of the code block
Properties made of key value pairs separated by commas
Closing of the code block
Semicolon
How do you remove a property from an object?
Delete obj.property
What are the two ways to get or update the value of a property?
Dot notation and bracket notation
What is a function in JavaScript?
A block of code that executes a task and can easily be called on
Describe the parts of a functiondefinition.
Function keyword, an optional name for the function, 0 or more parameters separated by commas enclosed by parentheses, opening curly brace for the code block
Optional return statement
End of the code block
Describe the parts of a functioncall.
The functions name, 0 or more arguments separated by commas enclosed in parentheses
When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
There is no function keyword in the call
The parameter is a representation of the actual argument
There is no code block in a function call
What is the difference between aparameterand anargument?
A parameter is part of a function definition and an argument is part of the function call
Why are functionparametersuseful?
It acts as a placeholder until you have the actual values when the function is called
What two effects does areturnstatement have on the behavior of a function?
It produces a value from the function
It ends the function code block from running anything else
Why do we log things to the console?
Using the log method of the console object console.log();
What is a method?
A function inside of an object
How is a method different from any other function?
It is part of an object while other functions are not
How do you remove the last element from an array?
Pop method (shift method to remove first element)
How do you round a number down to the nearest integer?
Math.floor();
How do you round a number down to the nearest integer?
Math.floor();
How do you generate a random number?
Math.random() The random method of the Math object
How do you delete an element from an array?
Splice method (first number is which index to before which index to start at, second number is how many elements to remove)