You may be wondering why anyone would want to write Kotlin code that is then transpiled to Kotlin? Why go through the extra work? What are the benefits? These are perfectly reasonable questions, and ultimately, will depend a lot on your own experience and needs. However, we can explore some of the benefits to help inform your own investigation and decisions.
One benefit of using Kotlin for JavaScript is that it's statically typed. Many developers find JavaScript's lack of static typing to be disorienting and something to be desired. As such, there have been new languages that pop up, such as TypeScript, that aim to bring static typing to the JavaScript world. In this sense, Kotlin is similar to TypeScript. As a developer, you can work with static types provided by Kotlin and let the compiler work out how to translate that into proper JavaScript.
If you're an individual or team targeting multiple platforms for the same project, Kotlin could provide an avenue to achieve common code sharing. By defining common code, such as models or generic business logic, in Kotlin, that code can then be reused across multiple targets, including JavaScript, Native, and Android/JVM.
If you're a developer that is already familiar with Kotlin, targeting JavaScript can make both frontend and backend web development more approachable. Working with a familiar language can lower the barrier to entry for working in a new domain. With Kotlin for JavaScript, we can write simple JavaScript scripts, manipulate the DOM, or even write Node.js server-side code. This makes Kotlin a very powerful tool for a mobile developer, for example, who could theoretically use the same language, or even some of the same code, to write a mobile app, backend, and a web app.
With all of this in mind, let's start writing our own Kotlin project that targets JavaScript so that we can start to gain a first-hand understanding of how it works and what's possible.