Skip to content

Clarify JS code inlining capabilities #4701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/topics/js/js-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ the surrounding tooling.

## Inline JavaScript

You can inline some JavaScript code into your Kotlin code using the [`js()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/js.html) function.
You can inline JavaScript code into your Kotlin code using the [`js()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/js.html) function.
For example:

```kotlin
Expand All @@ -26,11 +26,16 @@ a string constant. So, the following code is incorrect:
fun jsTypeOf(o: Any): String {
return js(getTypeof() + " o") // error reported here
}

fun getTypeof() = "typeof"
```

Note that invoking `js()` returns a result of type [`dynamic`](dynamic-type.md), which provides no type safety at the
compile time.
> As the JavaScript code is parsed by the Kotlin compiler, not all ECMAScript features might be supported.
> In this case, you can encounter compilation errors.
>
{style="note"}

Note that invoking `js()` returns a result of type [`dynamic`](dynamic-type.md), which provides no type safety at compile time.

## external modifier

Expand Down