s30 Discussion
s30 Discussion
log('Hello World');
const firstNum = 8 ** 2;
console.log(firstNum);
console.log(anotherMessage);
/*
- Template literals allow us to write strings with embedded JavaScript
expressions
- expressions are any valid unit of code that resolves to a value
- "${}" are used to include JavaScript expressions in strings using template
literals
*/
const interestRate = .1;
const principal = 1000;
// Pre-Array Destructuring
console.log(fullName[0]);
console.log(fullName[1]);
console.log(fullName[2]);
// Array Destructuring
const [firstName, middleName, lastName] = fullName;
console.log(firstName);
console.log(middleName);
console.log(lastName);
// Pre-Object Destructuring
console.log(person.givenName);
console.log(person.middleName);
console.log(person.familyName);
// Object Destructuring
const { givenName, maidenName, familyName } = person;
console.log(givenName);
console.log(middleName);
console.log(familyName);
getFullName(person);
/*
const variableName = () => {
console.log()
}
*/
// Arrow Function
/*
- Syntax
let/const variableName = (parameterA, parameterB, parameterC) => {
console.log();
}
*/
// Arrow Function
// The function is only used in the "forEach" method to print out a text with the
student's names
students.forEach((student) => {
console.log(`${student} is a student.`);
})
// Pre-Arrow Function
// Arrow Function
const add = (x, y) => x + y;
console.log(greet());
// console.log(greet("John"));
// Creating a class
/*
- The constructor is a special method of a class for creating/initializing an
object for that class.
- The "this" keyword refers to the properties of an object created/initialized
from the class
- By using the "this" keyword and accessing an object's property, this allows
us to reassign it's values
- Syntax
class className {
constructor(objectPropertyA, objectPropertyB) {
this.objectPropertyA = objectPropertyA;
this.objectPropertyB = objectPropertyB;
}
}
*/
class Car {
constructor(brand, name, year) {
this.brand = brand;
this.name = name;
this.year = year;
}
}
// Instantiating an object
/*
- The "new" operator creates/instantiates a new object with the given arguments
as the values of it's properties
- No arguments provided will create an object without any values assigned to
it's properties
- let/const variableName = new ClassName();
*/
// let myCar = new Car();
/*
- Creating a constant with the "const" keyword and assigning it a value of an
object makes it so we can't re-assign it with another data type
- It does not mean that it's properties cannot be changed/immutable
*/
const myCar = new Car();
console.log(myCar);
console.log(myCar);
// Creating/instantiating a new object from the car class with initialized values
const myNewCar = new Car("Toyota", "Vios", 2021);
console.log(myNewCar);