JS Flashcards
What is a variable?
Why are variables useful?
container that stores information such as strings, numbers, booleans etc
They are able to be reused and reassigned to a value; concise for readability
How do you declare a variable?
How do you assign a value to a variable?
var ( keyword ) = name( value )
( = ) assignment operator
What is a string?
What is the string concatenation operator?
0 or more characters inside quotes.
it is the data type stored in quotes
(+) Adds the first and second string together
How do you escape quotation characters?
( \ ) As a character to prevent interpreting a quote as the end of a string
What is type coercion?
Is the process of converting a value from one to another.
ex: number will become a string with concatenation
What is a number in JavaScript?
A primitive data type by literals
What is an arithmetic operator?
Name four of the arithmetic operators?
operator and operand; anything that can do math
+,-,*, /
What is a boolean?
Variable that can only have a value of true or false
What is a comparison operator?
=== ; same type and same content
What is the difference between undefined and null?
undefined: variable declared. but no value, it is default.
null: object, is an assignment value of nothing, needs to be set to Null. (assigned on purpose)
What is a function and why are they useful?
A function is a set of statements that perform a task. Functions are useful because they are expressions that can have a return value
How do you call a function?
What are the parts of a function definition?
function name(parameter ) { }
function keyword , function name , (parameters) { code block }
What is the difference between a parameter and an argument?
Parameter: Space prepared for data; variable in method definition
Argument: Value that goes into the variable. Data that is passed through parameters.
Why is it important to understand truthy and falsy values?
allow use the ability to use conditionals.
Falsy Values
if (false) if (null) if (undefined) if (0) if (-0) if (0n) if (NaN) if ("")
Truthy Values
if (true) if ({}) if ([]) if (42) if ("0") if ("false") if (new Date()) if (-42) if (12n) if (3.14) if (-3.14) if (Infinity) if (-Infinity)
Logical Operators:
and
or
not
&&
||
!
What happens if there is no break statement between cases?
It will fall through. it’ll run cases that fall below.
instead of switch statements, a conditional can be written.
What is an object in JavaScript?
data type that stores data
How do you create an object literal?
var keyword = { }
What is a property in relation to JavaScript objects?
it is a key-value pair
Dot notation?
object.property = value;