JavaScript Flashcards
What is the purpose of variables?
tto tem,porarily store information for the computer to use in order to get the desired result
How do you declare a variable?
using a keyword like var, const or let
How do you initialize (assign a value to) a variable?
you assign it a value with the equal operator
What characters are allowed in variable names?
$, letters and _underscore not numbers
What does it mean to say that variable names are “case sensitive”?
it means, the the same word written with different cases are two different variables
What is the purpose of a string?
holds words, inside quotation marks, can add written information for user, works with any kind of text
What is the purpose of a number?
to allow the computer to calculate as well as moving elements on a page, holds numeric value;
What is the purpose of a boolean?
to give the computer true or false data, it helps ‘check’ things, allows for true or false
What does the = operator mean in JavaScript?
ther assignment operator assigns a value to variable names
How do you update the value of a variable?
you do not have to declare it again, you just use the assignment operator
What is the difference between null and undefined?
undefined is the immediate value of a variable if it hasn’t been assigned a value or for formal arguments where there are nno actual arguments
In computer science, a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. The meaning of a null reference varies among language implementations.
null can also be used for a place to store a value to be changed later
Why is it a good habit to include “labels” when you log values to the browser console?
so that you keep track of your consoles
tells you what line number you’re on
Give five examples of JavaScript primitives.
null, undefined, string data, numeric data, boolean data
Difference between primitive and reference data types
primitives stores the variable in memory location
reference stores the address of where the information is
What data type is returned by an arithmetic operation?
Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.
A number
What is string concatenation?
Concatenate just means “join together”. To join together strings in JavaScript you can use a different type of string, called a template literal.
‘string’ + ‘string’
${string}
What purpose(s) does the + plus operator serve in JavaScript?
addition of number values, and string concatenation
+ operator if it receives two numbers it knows it needs to add,
if it receives a string, it knows to concantenate
What data type is returned by comparing two values (<, >, ===, etc)?
true or false, boolean
What does the += “plus-equals” operator do?
adds a value to the right and updates the variable
What are objects used for?
objects group together a set of variables and functions that create a model of something that exists in the real world
grouping variables together
What are object properties?
in an object, variables are known as properties - they can hold information like the name of a hotel
name: ‘Hilton’ -> that is the property
Describe object literal notation.
var object = { name(key): louisa(value) }
key value pairs
var keyword var object ope
How do you remove a property from an object?
delete operator
delete pet.name
What are the two ways to get or update the value of a property?
person.name
person[name]
dot or bracket notation
why use dot versus bracket notation?
bracket notation allows us to use a variable to store a property name
student.name can only be name
var prop = ‘color’
vehicle[prop] = ‘white’
^^ bracket is substition
bracket also allows to accessor create an illegal variable names
look at pictures
Objects are addresses, they point to the first point of data
you’re storing a reference to a memory base that points to the first value
reference data point
What are arrays used for?
to keep lists of data
Describe array literal notation.
variable is assign to the array object
How are arrays different from “plain” objects?
What number represents the first index of an array?
What is the length property of an array?
How do you calculate the last index of an array?
the length. -1
How do you calculate the last index of an array?
the length. -1
What is a function in JavaScript?
Describe the parts of a function definition.
function ex(hi, yo) {
var ex = y
return x}
Describe the parts of a function call.
function()
Callingthe function actually performs the specified actions with the indicated parameters. For example, if you define the functionsquare, you could call it as follows:
code inside the function will execute when “something”invokes(calls) the function:
When an event occurs (when a user clicks a button)
When it is invoked (called) from JavaScript code
Automatically (self invoked)
When comparing them side-by-side, what are the differences between a function call and a function definition?
Once defined, a function is just another kind of object. However, it is special in that it can be called. A function must be called for the code within its code block to run.
option key word Parameter {
code black}
What is the difference between a parameter and an argument?
Functionparametersare listed inside the parentheses () in the function definition.
Functionargumentsare thevaluesreceived by the function when it is invoked.
Inside the function, the arguments (the parameters) behave as local variables.
Why are function parameters useful?
act as variables and argyu8ments act more like value;
What two effects does a return statement have on the behavior of a function?
Why do we log things to the console?
The JavaScript console is a debugging tool. It is where the browser prints errors and warnings as they occur in your JavaScript code.
What is a method?
A method is a function which is a property of an object.
Random is the function - the value is what the function does
There are two kinds of methods: instance methods which are built-in tasks performed by an object instance, or static methods which are tasks that are called directly on an object constructor.
How is a method different from any other function?
In JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function.
Other than being a property of an object, difference is only that the method is assignedf to a property