Files
BroCodeJS/Practice/AdvancedThings/script.js
2024-10-11 10:55:09 +02:00

51 lines
1.2 KiB
JavaScript

//ES6 MODULES
import {PI, getCircumference, getArea, getVolume} from './mathUtil.js'; //Import functions and variables from another file
//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=27294
console.log(PI)
console.log("Circumference: " + getCircumference(5));
console.log("Area: " + getArea(5));
console.log("Volume: " + getVolume(5));
//ASYNC PROGRAMMING!!!
setTimeout(() => console.log("Task1"), 3000) //THIS IS AN ASYNC FUNCTION!!!! And because of that the tasks order will be 2, 3, and 1
console.log('Task2')
console.log('Task3')
//Force async functions to behave like synchronous
function func1(callback){
setTimeout(() => {console.log("Stask1");
callback();},3000);
}
function func2(){
console.log("Stask2");
console.log("Stask3");
}
func1(func2);
//ERROR OBJECTS
try{
console.log("HELLO");
const feellikeerror = false;
if (feellikeerror){
throw new Error("I felt like making an error!")
}
}
catch(error){
console.error(error)
}
finally{ //OPTIONAL It will always be executed!
console.log("This always executes!")
}
console.log("END!")