Javascript Flashcards
Key steps for variables
declaration: let, var, const
assignment: age = 25
let age = 25
variable conventions in Javascript is …
camelCase
eg. let numberOfApples = 9
Strings
stores text, string is surrounded with quotes ( ‘ ‘, “”, ``)
Numbers
Represent numerical data, integer or float (float means it has decimals)
Logical Operators
== (comparing the value only if equal)
!= (not equal in value)
!== (not equal in value and type)
=== (strictly equal in value and type)
Conditional Syntax
if ( condition is true) {
// do cool stuff
}
eg.
const pizza = “Dominos”
if (pizza === “Papa Johns”) {
console.log(“Scram”)
} else if(pizza === “Dominos”) {
console.log(“You got that right”)
} else {
console.log(“What you doing?”)
}
Multiple Conditions
OR
if (day === “Saturday” || day === “Sunday”) {
//it is the weekend.
}
AND
if (day === “Saturday” && day === “Sunday”) {
//it is the weekend.
}
Example of a Function Declaration
function sayHi() {
alert(‘Hello’)
}
Example of a Function Expression
let sayHi = function() {
alert(‘Hello’);
};
Example of an Arrow Function
sayHi = () => alert(‘Hello’);
What is a while loop?
A while loop lets you repeat a code while a certain condition is true.
The while loop repeats statements while a certain condition is true.
Example of a while loop
let number = 1;
while (number <= 5) {
console.log(number);
number++;
}
What is the while loop syntax?
while(condition) {
//this is called the body
// Code to run while the condition is true
}
What is an example of for loop?
let number;
for (number =1; number <= 5; number++) {
console.log(number);
}
What is the for loop syntax?
for (initialization; condition; final expression) {
// code to run while the condition is true
}