0

I am confused about scope in react.

const global = "Hey i am in global scope";
const component = () => {
  return <p>{global}</p>
}

Is it lexical?

Hidayt Raj
  • 13
  • 3
  • What's confusing you about the scope? The code example you included in your question, does it not work as you expect it to? BTW, react does not have its own rules for scope. Same rules of scope apply as in vanilla javascript. – Yousaf Jun 23 '21 at 10:14
  • Yes, Its working fine, but I just wanted to know, is this the lexical scope? – Hidayt Raj Jun 23 '21 at 10:15
  • Yes it is. You might want read: [What is lexical scope?](https://stackoverflow.com/questions/1047454/what-is-lexical-scope) – Yousaf Jun 23 '21 at 10:18

1 Answers1

0

React is a JavaScript library. The example you've mentioned is of lexical scope. It follows all principles of JavaScript. You can get more on scoping in the below links:

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Lovlesh Pokra
  • 722
  • 4
  • 14