JavaScript Flashcards
What is the purpose of a string?
To store texts that doesn’t make sense to Javascript
as a sequence of characters!
Purpose of a number?
to store numbers, not always mathematical values
ex) zip codes, phone numbers = numbers that are actually a type of IDs
Purpose of a boolean?
to make decisions/logic switches
What is the difference between null and undefined?
null = value is left out intentionally or coming later. Can only be created by coders by assigning null as the value of a variable
ex) var intentionallyEmpty = null;
undefined = Javascript can create this whenever! Causing ambiguity to the code/debugging steps
Why is it a good habit to include “labels” when you log values to the browser console?
It describes the value that is being logged creating more organization and clarity
7 examples of javascript PRIMITIVES vs JS data types?
string, boolean, number, bigint(numbers that are big), null, undefined, symbol
vs. all of the above AND objects
What is string concatenation?
to make multiple strings become one string
not mathematical, but still an expression (aka a chunk of work that javascript must perform)
uses string operator +
What is an object literal notation?
a simplified syntax = aka syntactical sugar of the constructor notation which uses a constructor function and “new” operator
method
properties that store functions
OR functions that are properties of an object
What are objects used for?
to group data/variables that are related
What are object properties?
individual place to store data within an object
basically a variable inside of an object
Describe object literal notation
{
property: value,
property: value
};
How do we remove a property from an object?
How do we clear the value of a property from an object?
delete operator with object name and property name
reassign the value using dot or bracket notation = ‘ ‘ (blank string)
How do we read this (using square bracket to assign a property and value of an object)?
vehicle[‘color’] = ‘white’;
string white is being assigned to the vehicle AT string color
What makes arrays a special type of object?
They hold a related set of key/value pairs, but the key for each value is its index number.
What are arrays used for?
to create a list and group like data with more flexibility in length/amount vs. object
What is the length property of an array?
shows how many items are inside the array
array.length
How are arrays different from “plain” objects?
arrays do not need a property/key name
the automatically generated name is the index number!
arrays have an order and length
requires method to add/delete data
vs
objects need property/key name
objects do not have order or length
objects require assignment operator to add
and delete operator to delete data
How do you calculate the last index of an array?
array.length - 1
What is a function in Javascript?
a special kind of object that is “callable”
repeatable named block of code
Parts of the Function Definition
Key word: function
optional name
optional parameter
{}
*likely a return statement
What is the difference between function parameter and argument?
Parameter = part of function definition (aka placeholders for potential value in the future) only exists inside of the function code block! This is what lets us reuse functions with different values!
Argument = part of function call
the value that we pass
What 2 effects does the return statement have?
- return of the function spits out a value = specifies a value to be returned to the function caller
- stops the function from running
we can use it to create Guard Clauses (used when we can’t prevent something from going wrong lol)
Does every function call have a return value?
Yes! Even if there is nothing specified, JavaScript will return UNDEFINED! If the code block has console.log, it will log whatever is specified.
ex) function greet () {
var greeting = ‘Hello’;
}
greet();
we will have undefined show up in our console