JavaScript Environment
#
JavaScript RuntimeWhen using React Native, you're going to be running your JavaScript code in two environments:
- In most cases, 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 both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.
#
JavaScript Syntax TransformersSyntax 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 metro-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 2019 (ES10) | |
Optional Catch Binding |
|
ECMAScript 2020 (ES11) | |
Dynamic Imports |
|
Stage 1 Proposal | |
Export Default From |
|
Stage 3 Proposal | |
Object Spread |
|
Static Class Fields |
|
Stage 4 Proposal | |
Nullish Coalescing Operator |
|
Optional Chaining |
|
Other Proposals | |
Class Properties |
|
Miscellaneous | |
Babel Template |
|
Flow |
|
ESM to CJS |
|
JSX |
|
Object Assign |
|
React Display Name |
|
TypeScript |
|
#
PolyfillsMany 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__