Interview frequency: …
Short answer
console.log operations are synchronous, pass through the Bridge, and serialize large objects into strings, causing noticeable freezes and dropped frames if left in production code.
Explanation
console is useful in development. But in a production build, logging hundreds of objects during every scroll frame heavily uses the CPU and Bridge and writes data to the phone's logs (Logcat/Console log), potentially exposing sensitive user data. Remove logs automatically with Babel plugins such as babel-plugin-transform-remove-console.
Code example
// In babel.config.js to automatically remove calls in production:
module.exports = {
presets: ['module:@react-native/babel-preset'],
env: {
production: {
plugins: ['transform-remove-console'],
},
},
};Common mistakes
- Leaving console.log calls for sensitive API data, such as passwords and cards, in a Release build.