JavaScript Environment
JavaScript Runtime
When using React Native, you're going to be running your JavaScript code in up to three environments:
- In most cases, React Native will use Hermes, an open-source JavaScript engine optimized for React Native.
- If Hermes is disabled, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
- When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
While these environments are very similar, you may end up hitting some inconsistencies. It is best to avoid relying on specifics of any runtime.
JavaScript Syntax Transformers
Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.
React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.
A full list of React Native's enabled transformations can be found in @react-native/babel-preset.
Transformation | Code |
---|---|
ECMAScript 5 | |
Reserved Words |
|
ECMAScript 2015 (ES6) | |
Arrow functions |
|
Block scoping |
|
Call spread |
|
Classes |
|
Computed Properties |
|
Constants |
|
Destructuring |
|
for…of |
|
Function Name |
|
Literals |
|
Modules |
|
Object Concise Method |
|
Object Short Notation |
|
Parameters |
|
Rest Params |
|
Shorthand Properties |
|
Sticky Regex |
|
Template Literals |
|
Unicode Regex |
|
ECMAScript 2016 (ES7) | |
Exponentiation Operator |
|
ECMAScript 2017 (ES8) | |
Async Functions |
|
Function Trailing Comma |
|
ECMAScript 2018 (ES9) | |
Object Spread |
|
ECMAScript 2019 (ES10) | |
Optional Catch Binding |
|
ECMAScript 2020 (ES11) | |
Dynamic Imports |
|
Nullish Coalescing Operator |
|
Optional Chaining |
|
ECMAScript 2022 (ES13) | |
Class Fields |
|
Stage 1 Proposal | |
Export Default From |
|
Miscellaneous | |
Babel Template |
|
Flow |
|
ESM to CJS |
|
JSX |
|
Object Assign |
|
React Display Name |
|
TypeScript |
|
Polyfills
Many standard functions are also available on all the supported JavaScript runtimes.
Browser
- CommonJS
require
console.{log, warn, error, info, trace, table, group, groupEnd}
XMLHttpRequest
,fetch
{set, clear}{Timeout, Interval, Immediate}, {request, cancel}AnimationFrame
ECMAScript 2015 (ES6)
Array.from
Array.prototype.{find, findIndex}
Object.assign
String.prototype.{startsWith, endsWith, repeat, includes}
ECMAScript 2016 (ES7)
Array.prototype.includes
ECMAScript 2017 (ES8)
Specific
__DEV__