跪拜 Guibai
← All articles
JavaScript

let Over var, === Over ==: The JavaScript Essentials Kotlin Devs Need

By Vic_wkx ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Mobile developers moving from Kotlin to JavaScript for React Native or Node get a direct translation of core syntax; the explanations of var's scope leaks and =='s coercion prevent silent bugs that are hard to spot.

Summary

JavaScript basics for developers who already know Kotlin: variable declarations, object literals, operators, functions, and async. The material explains why modern code uses `const` and `let`; `var` ignores block scope and leaks variables, a legacy that can't be removed without breaking old pages. It also shows why `==` is a trap (it coerces types, so `0 == ''` is true) and why strict `===` is the sane default, with optional chaining and nullish coalescing mirroring Kotlin's null safety.

Reusing object shapes comes in three forms: class syntax (closest to Java/Kotlin), a factory function returning an object literal, or TypeScript for projects where pure JS's missing type checking hurts. Functions cover default parameters, arrow functions as the JS name for lambdas, and `await` for async work. Each concept is mapped to its Kotlin counterpart, so mobile developers can transfer what they already know.

Takeaways
— `const` declares immutable bindings, `let` mutable ones; `var` is deprecated because it ignores block scope and leaks variables.
— JS has two empty values: `null` (explicitly set) and `undefined` (never assigned).
— Objects are created with object literals like `{ name: 'Tom', age: 18 }` and can gain new properties anytime.
— `==` performs implicit type conversion; `0 == ''` is true, so use strict `===` except when checking `x == null` to catch both null and undefined.
— For reusable object shapes, use `class`, a factory function, or TypeScript to enforce property names and types.
— Arrow functions are the JS name for lambdas; `await` works like Kotlin's suspend for async operations.
Conclusions

JS keeps legacy behavior like `var` and `==` for web compatibility, so modern fixes come as new syntax (`let`, `===`) rather than breaking changes.

The freedom to add properties to object literals makes pure JS flexible but pushes large projects toward TypeScript, which reintroduces structure.

Optional chaining and nullish coalescing bring Kotlin-style null safety into JS, reducing the gap between the two languages.

Concepts & terms
Type coercion
In JavaScript, `==` automatically converts operands to a common type before comparing, causing results like `0 == ''` being true.
Block scope
Variables declared inside `{}` are only visible within that block. The old `var` ignores this and leaks variables outside.
Strict equality
`===` compares both type and value without coercion; `0 === '0'` is false.
Nullish coalescing
`a ?? 0` returns `0` only when `a` is `null` or `undefined`, not for other falsy values like `0` or `''`.
From the discussion
Featured comments
2026再出发

Isn't iOS development just Swift?

Vic_wkx

Yes, but Swift feels a bit too heavy for me. I'm only learning iOS development to make an offline music player for my iPhone, and it looks like I can just use JS + Scriptable.

Vic_wkx

I recall the signing required to install a native iOS app comes with a lot of restrictions — it's not easy to deal with.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗