Before we get to the basics of JavaScript, we need to understand the purpose of this programming language.
The most famous use of JS is, of course, web development. Most often JS is used when you need to add dynamism to a site or make a browser application, but if you want, you can write a backend on it.
JavaScript is characterized by:
- prototypical programming style (prototypes and cloning instead of classes and inheritance);
- weak dynamic typing;
- functions as objects of the first class (i.e. they can be created at runtime).
Dynamic web pages
Tooltips, moving pictures, falling snowflakes and other animations – you can go to JS for all this. JS code is embedded in a web page, and when a user opens it, the script is executed directly in the browser.
Without JavaScript is almost impossible to create a full-fledged site. Add to JS knowledge of HTML, CSS, and you get a good set of skills for a beginner frontend developer. To complete the picture, you should master a couple of popular frameworks: for example, React, Svelte, Vue.js.
Web applications and games
JavaScript comes in handy here as well. For example, Google Maps and the Gmail web client use JavaScript. And if you want to write a game – take JS, HTML5, one of the ready-made libraries (say, EaselJS or PixiJS) and create your own browser-based game, three-in-a-row or whatever everyone is playing nowadays.
Browser extensions
Since JavaScript is based on executing code in the browser, it’s a great choice for creating browser extensions. Write your own email checker or, for example, an activity counter that keeps track of how much time you’ve spent working and how much time you’ve spent browsing social media.
Server applications
Yes, you can easily write a web server in JavaScript. But if JS has almost no competitors in the browser, then in the backend world it has to compete with other languages: PHP, Python and others. The main advantage of JavaScript in this battle is the ability to develop client and server side in the same language. To write backend in JavaScript, the Node.js engine is usually used – it allows you to execute JS code outside the browser.
Mobile apps
Perhaps not the most popular, but a very real application of JavaScript. Most often, mobile applications are developed in operating system-specific languages (Swift for iOS and Java/Kotlin for Android). JavaScript is good because it allows you to create cross-platform applications – you can use React Native, Ionic or PhoneGap frameworks for this purpose. Although JS has competitors here too – for example, Kotlin and Dart.
Desktop
JavaScript has made its way to desktop applications as well. For example, GitHub has combined the aforementioned Node.js, the Chromium rendering engine and developed the Electron framework, on which you can write cross-platform desktop projects. Examples include GitHub Desktop, Visual Studio Code, Skype, and WordPress Desktop. Electron has an analog – NW.js, which is mainly used to create desktop versions of websites and games.