← React / TypeScript

React / TypeScript · 01 / 18

JavaScript: your first program

Run a JavaScript file and understand the difference between a browser and Node.js.

  • Small
  • Basics
  • 15 min

Prerequisites: No prior knowledge required.

React is not a programming language. React interfaces are described using JavaScript or TypeScript. We start with JavaScript and text output. You do not need a website yet. Node.js runs JavaScript outside the browser. A browser also provides functions for web pages. Later we use React in both browsers and mobile apps.

Example files

01Prepare Node.js

Install Node.js 22 or newer from its official website. Open a terminal and check node --version. Create a new learning folder. A terminal executes commands while an editor edits files. You need both.

02Write code

Save the example as hello.mjs. .mjs identifies a JavaScript module. console.log writes a value to the console. Parentheses contain supplied values. Quotation marks make the contents text.

hello.mjs · javascriptOpen file
console.log('Hello, AppFabrik!');

Run / check

node hello.mjs

03Run and change

Run node hello.mjs in the file’s folder. Change the greeting, save and run it again. Unlike in a browser, document is not automatically available in Node.js. document belongs to a web page rather than the language itself.

Expected result

Hello, AppFabrik!

Your exercise

Print a second line containing your first name. Also open your browser’s developer console and execute the same console.log call.

Show the solution and explanation

Add console.log("Your name"). Both environments understand this call. Output goes to the terminal or browser console respectively. This does not prove that every other API exists in both environments.

Project context and sources

The example is simplified for learning. The linked source version shows its use in the project and the checks applied there.