Skip to main content

Javascript Functions

There are a lot of ways to write function in Javascript. Here are a few examples.

Immediately-invoked Functions

To have a function run automaticlly you can use the following:

(() => {
console.log('Hello World')
})();

The async/await version would be:

(async () => {
await myAsyncFunction();
})();

Here is an example with error handeling:

(async () => {
// some working code
})().catch(err => {
console.error(err);
});