Node: {
content: any,
next: Node
}
LinkedList: {
head: Node,
tail: Node
}
newLinkedList() -> LinkedList
newNode(content) -> Node
add(Node, LinkedList) -> null
delete(Node, LinkedList) -> null
let x = 1;
const y = 2;
if (condition) {
// do something
}
while (condition) {
// do something
}
for (let i = 0; i < arr.length; i++) {
// do something
}
function test(arg1, arg2) {
// do something
}
const arr = ['foo', 'bar', 'baz']
arr[0] // "foo"
arr[1] // "bar"
arr[2] // "baz"
const car = {
color: 'red',
fuel: '50%',
topSpeed: 200
}
car.color // "red"
car.fuel // "50%"
car.topSpeed // 200
class Car {
velocity = 250
constructor(color, fuelType) {
this.color = color;
this.fuelType = fuelType;
}
paint(newColor) {
this.color = newColor;
}
static hasTheSameProperties(car1, car2) {
return car1.color === car2.color &&
car1.fuelType === car2.fuelType;
}
set fuelType(newFuelType) {
newFuelType = newFuelType.toLowerCase();
if (newFuelType !== 'electric' && newFuelType !== 'diesel') {
throw new Error('unsupported fuel type ' + newFuelType)
}
this._fuelType = newFuelType;
}
get fuelType() {
return this._fuelType;
}
}
class Prius extends Car {
constructor(color) {
super(color, 'Hybrid');
}
set fuelType(newFuelType) {
this._fuelType = 'Hybrid';
}
get fuelType() {
return this._fuelType;
}
}
// this code runs synchronously
doSomething();
doAnotherThing();
// this code runs asynchronously
doSomethingInTheBackground(callMeWhenDone);
doSomethingWithoutWaitingForPreviousLineToFinish();
function callMeWhenDone() {
console.log(
"doSomethingInTheBackground has finished");
}
// this code runs synchronously
doSomething();
doAnotherThing();
// this code runs asynchronously
doSomethingInTheBackground(callMeWhenDone);
doSomethingWithoutWaitingForPreviousLineToFinish();
function callMeWhenDone() {
console.log(
"doSomethingInTheBackground has finished");
}
function doSomethingInTheBackground(callback) {
setTimeout(callback, 1000);
}
// this code runs synchronously
doSomething();
doAnotherThing();
// this code runs asynchronously
doSomethingInTheBackground().then(callMeWhenDone);
doSomethingWithoutWaitingForPreviousLineToFinish();
function callMeWhenDone() {
console.log(
"doSomethingInTheBackground has finished");
}
function doSomethingInTheBackground(callback) {
return new Promise(function() {
// do stuff
})
}
// this code runs synchronously
doSomething();
doAnotherThing();
// this code runs asynchronously
await doSomethingInTheBackground();
WaitForPreviousLineToFinishThenDoSomething();
async function doSomethingInTheBackground(callback){
// do stuff
}