While originally a client-side language (meaning it is interpreted and processed in the user browser), thanks to Node.js it can now also run server side. In addition, React Native and Iconic brought it to mobile devices, Electron to desktop.
In recent years, the programming language has become more and more popular. In the Stack Overflow developer survey of 2021 it was voted the most popular programming language among professional developers. For the ninth year in a row!
// Nothing in this line will be executed
Those familiar with PHP will feel right at home as the two languages mark comments in the same way.
To get the above, simply open up the console in your browser developer tools and paste the following code:
Pretty easy to understand, right? When you now hit enter, you should see the same message as above.
With this knowledge, it’s already possible to try it out for yourself. Simply change the string inside the brackets (make sure to put it in quotation marks) to whatever you want to create your own popup.
Manipulating the DOM
Above, we have created a simple HTML page. As you can see, its has a heading and an empty paragraph element with an ID of target (if you don’t know about HTML classes and IDs, you can learn more here).
- document — Accesses the document object, which is the web page.
- getElementByID(“target”) — Finds an element according to its ID. The bracket contains the ID to look for in quotes.
- innerHTML — Changes the inner HTML of an element.
When you put them together, the script basically searches the web page for an element that has an ID of target and adds to its inner HTML. What it should include in that place is located behind the equal sign inside the double quotes. As a consequence, when you access a file with the above code in a browser, you see this:
What About Frameworks?