So what exactly is JavaScript? I’m confused

Time:2021-1-26

preface

It is quoted from JavaScript advanced programming fourth edition: “from simple input verification script to powerful programming language,JavaScriptNo one predicted the rise of China’s economy. It’s very simple, it takes only a few minutes to learn to use; it’s very complex, it takes many years to master it. We should really learn to use it wellJavaScriptIt is very important to understand its essence, history and limitations.

interviewer:JavaScriptWhat is it?
Me: EMJavaScriptnamelyJavaScript… 👀

Imagine if the interviewer asks you:JavaScriptWhat is it? What would you say? To be honest, when I heard this question, my mind was blank for a moment. We’ve been learning the front end for so long, even the simplest"What is JavaScript?"You can’t tell the interviewer why. Let’s talk about this today. When the interviewer asks youJavaScriptWhen is it? What points can you start from? Say as much as you can and make a good impression on the interviewer.

JavaScriptWhat is the positioning of the company?

1. JavaScriptIt’s a scripting language

Why a scripting language? Let’s take a brief look atJavaScriptThe ups and downs of the advent, in a word, Netscape company in 1995 to solve the problemCommunication delay between client and server in simple form verificationA new one calledJavaScriptAt that time, Microsoft decided to invest more resources in IE and launch it specificallyJScriptAnd then toEcma(European Association of computer manufacturers)ECMAScript(pronounced “EK Ma script”) international standardizes two languages to solve the problem of two versions coexisting.

What can scripting languages do? It can achieve complex functions on the web page, including the operation of theDOMElementsCSSStyle, can realize interactive map,2D/3DAnimation, scrolling video, etc.JavaScriptIt has a very powerful and flexible ability in the host environment, which provides more possibilities for developers.

2. JavaScriptIt’s a weakly typed language

This means that a variable can be implicitly converted to another type. Type of hidden conversion, giveJavaScriptWith a certain degree of flexibility, but also increases the complexity of the rules and the possibility of errors.

  • Binary operator+Converts both operands to a string, unless both operands are numeric. that is because+It can also be used to connect strings.
  • Binary operator-Converts two operands to numeric types.
  • Unary operators, including + and -, convert operands to numbers.
console.log(1 + '2' === '12')
// true
console.log('3' - '1' === 2)
// true
console.log(+'1' === 1)
// true
console.log(-'1' === -1)
// true

3. JavaScriptIt’s dynamic

  • Like most scripting languages, their types are associated with values, not variables. For example, a variable can be numeric and then assigned to a string.
let a = 233
A ='tantiedan '
console.log(a)
//'tantiedan '
  • JavaScript statements can be executed directly at run time
eval(" console.log ('students playing iron eggs') ")
//'tantiedan '

4. JavaScriptIt’s single threaded

JavaScriptNeed to interact with the page, operationDOMIf it is multithreaded, it will bring a very complex synchronization problem. For example, supposeJavaScriptThere are two threads at the same time, one thread in aDOMWhen content is added to a node and the node is deleted by another thread, which thread should the browser follow? So it can only be single threaded,

5. JavaScriptInterpretative language

Interpreted language is a kind of programming language. This type of programming language will run the code sentence by sentence directly, and it does not need to be compiled into machine code by compiler before running, just like compiled language.

6. JavaScriptIt has good cross platform performance

Cross platform features, under the support of most browsers, can run in a variety of platforms (such asWindows、Linux、Mac、Android、iOSEtc.).

JavaScriptandECMAScriptWhat’s the difference between, and betweenDOM 、BOMWhat’s the relationship?

First, a brief summaryECMAScript、 DOM 、BOMThree concepts.

DOM

DOM(document object model), which provides a way to interact with web contentmethodandInterface。 DOMThe whole page is abstracted as a group of hierarchical nodes.HTMLorXMLEach component of a page is a node that contains different data.DOMBy creating a tree representing documents, developers can control the content and structure of web pages at will. useDOM APIIt can easily delete, add, replace and modify nodes.

<html>
        <head>
            <title>Sample Page</title>
        </head>
        <body>
            <p> Hello World!</p>
        </body>
</html>

So what exactly is JavaScript? I'm confused

BOM

BOM(browser object model), which provides the interface for interaction with browsermethodandInterface。 BOMMainly for browser window and sub window (frame). useBOM, developers can control the browser to display parts outside the page, such as:

1) Ability to pop up new browser windows;
2) Ability to move, zoom and close browser windows;
3)navigatorObject to provide detailed information about the browser;
4)locationObject, which provides the detailed information of the browser loading page;
5)screenObject to provide detailed information about the resolution of the user’s screen;
6)performanceObject, which provides detailed information of browser memory usage, navigation behavior and time statistics;
7) For browser storage related operations, such ascookies、sessionStorage 、localStorage Etc;
8) Other custom objects, such asXMLHttpRequestandIEOfActiveXObject;

ECMAScript

ECMAScriptThis paper describes the syntax and basic objects of javascript: 1) syntax; 2) type; 3) statement; 4) keyword; 5) reserved word; 6) operator; 7) global object; 4) object;

ECMArelease262The first edition of ecma-262 specifies the standard of browser script language, which is called “browser script language”ECMAScriptThis version is1.0So the one sentence description is,ECMAScriptIt’s a set of norms,JavaScriptthen isECMAScriptAn implementation. Why is it an implementationAdobe ActionScriptThe same is trueECMAScript,JScriptThe same is trueECMAScript。

[ES[version related]

relationship

So after a brief understanding of the above key concepts, we can easily get the relationship between them! There is such a picture in “JavaScript advanced programming fourth edition”, which willJavaScript 、ECMAScript、 DOM 、BOMThe relationship between the four is very clear.

So what exactly is JavaScript? I'm confused

We come to the conclusion that ECMAScript, DOM and BOM are components of JavaScript.

summary

So at the end of the article, when the interviewer asks, “what is JavaScript,” we know where to start and where to start. So if we make the main points of this article clear to the interviewer, I believe we can leave a not too bad impression on the interviewer

  • JavaScriptThe positioning of

    • JavaScriptIt’s a scripting language
    • JavaScriptIt’s a weakly typed language
    • JavaScriptIt’s dynamic
    • JavaScriptIt’s single threaded
    • JavaScriptInterpretative language
    • JavaScriptIt has good cross platform performance
  • JavaScriptandECMAScriptThe difference between, andDOM 、BOMThe relationship between

    • DOM(document object model), which provides a way to interact with web contentmethodandInterface
    • BOM(browser object model), which provides the interface for interaction with browsermethodandInterface
    • ECMAScriptDescribedJavaScriptGrammar and basic objects of

Finally, I’d like to quote the opening paragraph, “it’s very important to understand the essence, history and limitations of JavaScript in order to really learn and use JavaScript well.”~

  • For more interesting and interesting articles, please pay attention to the official account.Front end iron egg“Yes
  • GitHub original

reference resources