Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

Why can I use a variable before declaring it in JavaScript / TypeScript?

$
0
0

To my understanding, after ES6 and the introduction of let and const, a variable declared with them must be declared before it's used. However, I have run into many examples where my code runs just fine when I declare the variables after its use. For example, this is the code from (a simplified version of) the TypeScript template of React Native:

import React from 'react';import {StyleSheet, Text} from 'react-native';const App = () => {  return (<><Text style={styles.text}>Some text</Text></>  );};const styles = StyleSheet.create({  text: {    backgroundColor: 'blue',  },});export default App;

Here, styles are declared after they are used, and it even seems to be the idiomatic way to do it, but even ESLint highlights as no-use-before-define.

My question is: why does it still work?


Viewing all articles
Browse latest Browse all 6213

Trending Articles