Lecture 5: Javascript: Basics Flashcards
Variables
let message = ‘Welcome’
Variable declaration
Let: for true variables you might want to re-assign
Const: for variables that are not re-assigned
Var: old, replaced by ‘let’.
Types
No Types are declared, JS dynamically assigns data types.
Variable names
cannot start with numbers, cannot start with keywords and ARE case-sensitive
Number
Numeric types(64 float)
String
text
Boolean
true/false
Null
lack of value
Undefined
never defined
Strict Equality
===
If statement
if(i === 6){
Do Something
}
else{
Do something else
}
What is True or False?
All evaluated as false:
False, null, undefined, “”, 0, NaN
What is True or False? All evaluated as True
True, “hello”, “false”, 1, -1
Arrays
A collection of data
Zero-based indexing
Example:
Let students = [“Alex”, “Ralph”, “Michael”, “Eric”];
for loop
Classic for loop. Counting things & operating via indices
for( let i = 0; i <students.length; i++){
Let name = students[i];
console.log(“Hi “ + name + “! You are at spot “ + i);}