9

See the title. When calling fetch in our react project, a (now departed) developer originally used from fetch to window.fetch. I'm not sure of the difference and can't find anything conclusive online (W3Schools doesn't even mention fetch as a function of the window)

3
  • 4
    Fetch is a function on the window object. You don't need to specify window.fetch in most cases as the global scope is window. There is no difference. Commented Sep 12, 2019 at 4:41
  • 4
    press F12 and type fetch === window.fetch. Same thing. Commented Sep 12, 2019 at 4:42
  • 2
    W3Schools doesn't mention a lot of things. Commented Sep 12, 2019 at 4:59

1 Answer 1

19

On your developer console, try this experiment:

fetch === window.fetch 

You'll see that this returns true. They are in fact the same thing.

window is the global object in a browser context. The browser APIs (distinct from language features) are found on the global window object.

Sign up to request clarification or add additional context in comments.

3 Comments

"Much of the framework you're using is built on the window object." --- this is a weird one.
@zerkms Feel free to re-word if you have a better way to describe it.
"All browser APIs are provided through the window global object." ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.