JavaScript 0130 Flashcards
What is the purpose of variables?
*To have a place to store data to be used later
How do you declare a variable?
using an assignment operator, e.g. “var”, and naming it within the confines of naming. it does not need to be initialized/assign to be declared
How do you initialize (assign a value to) a variable?
initialize is assign. use “=” and then assign its value
What characters are allowed in variable names?
$ _ letters numbers
What does it mean to say that variable names are “case sensitive”?
e.g. fullname and fullName are two different variables
What is the purpose of a string?
for text content
What is the purpose of a number?
store numbers to be used for things like calculation
What is the purpose of a boolean?
for decision making
What does the = operator mean in JavaScript?
it is used for declaring varables
How do you update the value of a variable?
type its name, then “=”, then the new value
What is the difference between null and undefined?
und var is not defined, null is like a placeholder
Why is it a good habit to include “labels” when you log values to the browser console?
so you can distinguish them in the console
Give five examples of JavaScript primitives.
number, string, bulion, undefined, null
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
joining data (strings?) with the + operator
What purpose(s) does the + plus operator serve in JavaScript?
to add numbers in calculations, to join data thru concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
a boolean
What does the += “plus-equals” operator do?
it adds
What are objects used for?
for storing data with descriptions, or keys/objects
What are object properties?
a variable becomes a property in an object
Describe object literal notation.
you create an object by using “var”, e.g., “=”, then “{“, so:
var person = {name: colin, hobby: cycling}
How do you remove a property from an object?
use the delete keyword, e.g. “delete person.name”
What are the two ways to get or update the value of a property? (give two examples of updating and two of getting)
bracket and dot notation, e.g.:
console.log(person.name)
console.log(person[name])
person.name = “colin”
person[“name”] = “colin”
what’s another word for “property” in objects?
a property can be called a key, and with a value is called a “key value pair”
when is bracket notation better?
when dealing with invalid variable names
What are arrays used for?
Describe array literal notation.
How are arrays different from “plain” objects?
they are indexed numerically?
What number represents the first index of an array?
zero
What is the length property of an array?
(.length) tells us how long an array is
How do you calculate the last index of an array?
.length - 1
what is a word for “[ ]”?
in arrays, the brackets “[ ]” can be thought of as “at”
what are the parts of a function’s syntax?
// [1] [2] [3]
function example(parameter1, parameter2, parameter3, …) { // [4]
// …more JavaScript code…
// [5]
return;
} // [6]
The function keyword to begin the creation of a new function.
An optional name. (Our function’s name is sayHello.)
A comma-separated list of zero or more parameters, surrounded by () parentheses. (Our sayHello function doesn’t have any parameters.)
The start of the function’s code block, as indicated by an { opening curly brace.
An optional return statement. (Our sayHello function doesn’t have a return statement.)
The end of the function’s code block, as indicated by a } closing curly brace.
What is a function in JavaScript?
a block of lines of code which can be called to perform actions
Describe the parts of a function definition.
Describe the parts of a function call.
name of function and parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
skip?
What is the difference between a parameter and an argument?
parameter like placeholder
argument is what goes in placeholder
Why are function parameters useful?
giving the function what it needs to run
What two effects does a return statement have on the behavior of a function?
stops the code from running, and tells computer what to return