diff --git a/2-ui/1-document/01-browser-environment/article.md b/2-ui/1-document/01-browser-environment/article.md index ce6fe0ba..6fd596b9 100644 --- a/2-ui/1-document/01-browser-environment/article.md +++ b/2-ui/1-document/01-browser-environment/article.md @@ -1,10 +1,10 @@ # Browser environment, specs -The Javascript language was born for web browsers. But as of now, it evolved and became a language with many use cases, not tied to browsers. +The Javascript language was initially created for web browsers. But as of now, it evolved and became a language with many uses and platforms. -The Javascript standard though assumes that the execution happens in a *host environment*, say Node.JS server, or a web-browser. +A platform may be either a browser or a web-server or a washing machine or another *host*. Each of them provides platform-specific functionality. The Javascript standard called that a *host environment*. -That host environment may provide additional objects and functions though. Web browsers provide means to control web pages. Node.JS provides server-side features. There are other host environments too. +That host environment provides additional objects and functions to the language core. Web browsers provide means to control web pages. Node.JS provides server-side features. There are other host environments too. [cut] @@ -12,83 +12,101 @@ Here's a bird-eye view of what we have when Javascript runs in a web-browser:  -On the top, there's `window` -- the object has two meanings: +The "root object" called `window` has two roles: -1. First, it is a [global object](info:global-object) in terms of Javascript. -2. Second, it represents the "browser window" object, supports methods to control it and read its parameters. +1. First, it is a [global object](info:global-object) for JavaScript code. +2. Second, it represents the "browser window" object, provides methods to control it. -For instance, to see the window height: +For instance, here we use it as a global object: + +```js run +function sayHi() { + alert("Hello"); +} + +alert(window.f); // global function is a property of window +``` + +And here we use it as a browser window, to see the window height: ```js run alert(window.innerHeight); // some number ``` -Now we go from left to right. - ## Document Object Model (DOM) -The `document` object gives access to a webpage contents. We can change or create literally anything. +The `document` object gives access to a page contents. We can change or create literally anything. For instance: ```js run +// change the background color to red document.body.style.background = 'red'; -alert('The
element became red! In 1 second it will become normal.'); + +// change it back after 1 second setTimeout(() => document.body.style.background = '', 1000); ``` -There are two working groups who develop the standard: +Here we used `document.body.style`, but there's much, much more. Properties and methods are described in the specification. + +There are two working groups who develop it: 1. [W3C](https://en.wikipedia.org/wiki/World_Wide_Web_Consortium) -- the documentation is at