Javascript
Syntax of the Javascript programming language
Variables
javascript
const FirstName = "Tutorial"
const LastName = "Doctor"
const BirthYear = 1985
const Height = 6.3
const EmailAddress = "td@gmail.com"
const IsAlive = true
javascript
apple = {
color: "red",
shape: "round",
weight: .33,
texture: "smooth"
}
orange = {
color: "orange",
shape: "round",
weight: .44,
texture: "bumpy"
}
Statements
javascript
console.log("Hello There!");
alert("Hello");
confirm("Are you sure?");
Try Catch
javascript
try {
console.log(x)
} catch (exceptionVar) {
console.log("An error occurred")
console.log(exceptionVar)
} finally {
console.log("Checks complete")
}
Conditional Statements
Functions
javascript
function add(number1,number2){
return number1 + number2
}
console.log(add(2,3))
Loops
Classes
javascript
class Car {
constructor(name, year) {
this.name = name;
this.year = year;
}
age() {
const date = new Date();
return date.getFullYear() - this.year;
}
}
const myCar = new Car("Ford", 2014);
const myCar2 = new Car("Audi", 2019);
document.getElementById("demo").innerHTML =
"My car is " + myCar.age() + " years old.";
Libraries
The DOM
The document object model (DOM) is...