# Browser vs Node.js

Is same code can be executed in chrome javascript engine as well as in nodejs since both are based on v8 engine. Well yes & no, I am not trying to create confusing here, but although both are based out of v8 engine. Still there is a difference between the ways of handling javascript code.

One resides inside your browser while other runs directly over os layer. In browser everything revoles around document object model (dom) while inside nodejs echo system, we don't have anything like dom.

To verify this open your browser javascript console and in seperate terminal type node. Type document in the chrome console.

![](https://akoserwal.gitbooks.io/how-it-feels-to-learn-javascript/content/assets/Screenshot%20from%202017-06-17%2020-50-26.png)

![](/files/-LGE2b5SLxLpYr-Yss-Y)

Open a terminal and type node.

```
> document
ReferenceError: document is not defined
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:336:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:533:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:238:10)
    at REPLServer.Interface._line (readline.js:582:8)
> window
ReferenceError: window is not defined
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:336:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:533:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:238:10)
    at REPLServer.Interface._line (readline.js:582:8)
```

You can see the difference in browser and node js console. document and window keywords are not defined inside node.js echo system while in browser, they provide you details about each in details. if you observe closely window keyword expose all the api's that can be used to call or modify specific element in the browser.[<br>](https://akoserwal.gitbooks.io/how-it-feels-to-learn-javascript/content/chapter1/nodejs.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://akoserwal.gitbook.io/how-it-feels-to-learn-javascript/nodejs/browser-js-engine-vs-node.js.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
