Hello World in Mercury

Our first program will print the classic “hello world” message. Here’s the full source code.

console.log("hello world");

To run the program, save the code in a file named hello-world.js and use node to execute it.

$ node hello-world.js
hello world

Sometimes we’ll want to package our JavaScript programs in a way that makes them easier to distribute. In JavaScript, this often involves bundling the code using a tool like Webpack.

First, install Webpack and Webpack CLI globally:

$ npm install -g webpack webpack-cli

Then, create a configuration file named webpack.config.js:

const path = require('path');

module.exports = {
  entry: './hello-world.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  mode: 'development'
};

Now, you can bundle your JavaScript code:

$ webpack

This will create a bundle.js file in the dist directory. You can then execute or include this bundled file in your HTML.

Now that we can run and bundle basic JavaScript programs, let’s learn more about the language.