JavaScript Basics Flashcards
What is the principal use of arrays?
to store ordered lists of data
Describe the syntax (structure) of array-literals in JavaScript.
var array_name = [item1, item2, item3,…] ;
How can you access the last element of an array?
const fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
let fruit = fruits[fruits.length - 1];
What data types can object properties hold?
booleans strings numbers undefined null
Describe the syntax (structure) of object-literals in JavaScript.
var person = {firstName:”John”, lastName:”Doe”, age:50, eyeColor:”blue”};
What does the = (equals) operator do in JavaScript?
assignment operator: assigns the value to a variable
**does NOT mean “equal to”
Which keyword is used to declare a variable in JavaScript?
var
let
const
Which characters is a JavaScript variable allowed to begin with?
upper or lowercase letter
$ dollar sign
_ underscore
What are quotation marks used for in JavaScript?
text strings
What is the purpose of variables?
to store data values
What is the purpose of strings in JavaScript?
storing & manipulating text
What is the purpose of booleans in JavaScript?
logic to represent 1 of 2 values
true/false
on/off
yes/no
What is the purpose of numbers in JavaScript?
to represent and manipulate numbers
definition:
Null vs Undefined
null - intentional absence of any OBJECT value (put there by programmer as ex/ var nothing = null)
undefined - value never assigned (default value of variable ex/ var never)
What is the purpose of objects?
To group together set of variables and fxns to create a model of something from real world
What are the two ways to get or update the value of a property?
dot notation bracket notation (substitutions)
variables & memory location
objects & memory location
REFERENCE (objects) !== PRIMITIVES
var a = b b can sometimes =/ a
obj a = obj b
they are the same because they are pointing to same memory address (and modifying that address)
What data type do comparison expressions evaluate to?
booleans
Give 6 examples of comparison operators.
=== !== >< <= >=
What is the purpose of an if statement?
evaluates to a boolean
conditionally run code based on boolean value of expression
Describe the syntax (structure) of an if statement.
if (condition) {
run code
}