Kotlin/js

·

3 min read

Kotlin/js

Kotlin has become a very prominent programming languages with many uses and has been adopted by so many big tech companies such as Google, Netflix, Amazon but to mention a few. This is because of how easy and diverse it is to both use and write code in. One of the uses is that it offers you the ability for write Kotlin code, libraries and any compatible dependencies to JavaScript, this is called the Kotlin/JS. You can achieve this by either using the kotlin.js or kotlin.multiplatform Gradle plugins.

This comes in handy when as a Kotlin developer you would like to now move to creating web apps using Kotlin. This enables you to still be able to use your Kotlin knowledge to write code for web apps, the server side and even serverless applications.

So, why then should you use Kotlin for JavaScript when you can simply just use JavaScript and it’s many frameworks and libraries?

  1. Use Kotlin Multiplatform projects to share code with other Kotlin targets
  2. Write full type-safe React apps
  3. Write server side and serverless apps
  4. Write front-end web apps
  5. Create libraries for use with JavaScript and TypeScript

Use Kotlin Multiplatform projects to share code with other Kotlin targets

When you write your projects using Kotlin/JS, you can easily access all the functionality using the multiplatform Gradle plugin. This allows you to target multiple platforms at once and you only have to write code once. This saves time and effort as you do not have to write the same code but differently for different platforms as the multiplatform Gradle plugin covers that for you.

Write full type-safe React apps

You can write type-safe React applications with Kotlin/JS using the Kotlin wrappers that are provided to you by JetBrains. The Kotlin wrappers also provide support for a selected number of adjacent technologies such as react-redux, react-router, or styled-components. Kotlin/JS also provides with access to other third-party React components and libraries.

Write server side and serverless apps

With the Kotlin/JS, you can write code for the server side using the Node.js target that is provided to you Kotlin/JS. With this, you can create applications that run on the server or get executed on serverless infrastructure.

Write frond-end web apps

Kotlin/JS allows you to fully utilise the browser and web APIs in a type-safe manner. You can create, modify and interact with the DOM elements. The Kotlin code allows you to control the rendering of the canvas or WebGL components.

Create libraries for use with JavaScript and TypeScript

You can generate libraries from the Kotlin code that will be used by the modules from any code base that is written in JavaScript or TypeScript. In so doing, you are able to reduce code duplication and harness the power of creating hybrid applications.

Kotlin for JavaScript is very powerful once you familiarise yourself with how it works and what benefits you will get by using it to write your applications. There are many more uses for the Kotlin/JS that can be found here

Connect with me on:

Twitter

LinkedIn

GitHub