The Basic javascript "Hello world"
The beginning
Last updated
The beginning
Last updated
Going back to basics allows us to review knowledge and, or we can put it this way, connect the dots on ambiguous aspects.
Before tackling React, maybe we should review how to make a basic web page using Vanilla JavaScript.
Basically, the most minimal thing that we can call a web page is just one HTML File that says "Hello world".
Like this one
The browser parses this HTML code and creates the DOM (Document Object Model). The browser, then, exposes the DOM to JavaScript. At that point, your web page will become interactive where you can do the basic events that we will talk about in another Section.
To read more about the Document Object Model (DOM):
Now, if we want to add some JavaScript we can just use the script tag
ES6 modules
In order to ensure that the ES6 features to works, the <script>
tag in your HTML file will need to have the attribute type="module"
. Surprisingly, this actually works as-is in most modern browsers.
The first question ever that I asked myself was how can JavaScript interact with the DOM?
How can I really create, modify or delete DOM element using JavaScript? These questions lead to my two first JavaScript commands I wrote:
The DOM represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree. With them, you can change the document's structure, style, or content.
Manipulating an Element is easy we can add styling or getting and adding content. Let's try to play with some stuff
As you can see, I added the id selector and the class selector to the root element. I added some styling and even added our "hello world" text.
Since we are always able to use HTML tags to create the div element with its attributes, I just wanted to show how JavaScript can leverage all of that in code.
People were creating HTML on the server and then layering JavaScript on top of it for interactivity. However, as the requirements for that interactivity grew more difficult, this approach resulted in applications that were difficult to maintain and had performance issues.
As a result, instead of defining the DOM in hand-written HTML, modern JavaScript frameworks were developed to address some of the issues like our beloved React.