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
}
What is the meaning of initialization on for loop?
Initialization only happens once, when the code first kicks off. It’s often used to set the initial value of the variable associated to the loop condition.
What is the meaning of the condition on for loop?
The condition is evaluated once before the loop runs each time. If it’s true, the code runs. If not, the code doesn’t run.
The for loop gives the ability to manage what happens just before the loop starts and after each loop iteration has run.
What is the meaning of the final expression on for loop?
The final expression is evaluated after the loop runs each time. It’s often used to update the value of the variable associated with the loop condition, as we saw in the previous example.
What does iteration mean?
Each repetition in your code.
What are loops used for?
It is used to repeat a series of statements.
How to create a form in HTML?
<form>
<label> First Name:</label>
<input></input><br></br>
</form>
Example of Javascript
HTML FILE
<h1>Your Name</h1>
<form>
<label>First Name</label>
<input></input>
</form>
<button>Yell</button>
<h2></h2>
JAVASCRIPT FILE
document.querySelector(‘#yell’).addEventListener(‘click’, yell)
function yell() {
const fName = document.querySelector(‘#firstName’).value;
const upperCaseName = fName.toUpperCase();
document.querySelector(‘#placeToYell’).innerText = upperCaseName;
}
What are variables?
Are buckets.
We can tell our program to remember values for us to use later on.
The entity we use to store the value is called a variable