Front End interview Knowledge Point Brocade set JavaScript

Source: Internet
Author: User

Where will the CSS block, and where the JS block will appear?

The blocking characteristics of JS:

All browsers in the download JS, will block all other activities, such as the download of other resources, content rendering and so on. Until JS downloads, parses, executes, and then continues to download additional resources and render the content in parallel. In order to improve the user experience, the next generation of browsers support parallel download js, but JS download will still block the download of other resources (such as. Pictures, CSS files, etc.).

Because the browser needs to rebuild the DOM tree in order to prevent JS from modifying the DOM tree, other downloads and renders are blocked.

Embedded JS will block the rendering of all content, while external JS will only block the display of subsequent content, 2 ways will block the subsequent download of resources. This means that external styles do not block the loading of external scripts, but they block the execution of external scripts.

How can CSS block loading?

CSS can be downloaded in parallel, under what circumstances will be blocked loading (in the test observation, IE6 under the CSS is blocked loading)

When the CSS is followed by the embedded JS, the CSS will be blocked after the download of the resource situation. When you put the embedded JS in front of the CSS, there will be no blocking situation.

Root cause: Because the browser will maintain the HTML in the order of CSS and JS, the stylesheet must be loaded before the embedded JS execution, parsing finished. Embedded JS will block the subsequent loading of resources, so the above CSS blocking download situation.

Where should JS be placed?

(1), on the bottom, although placed at the bottom will still block all rendering, but does not block the download of resources.

(2), if embedded JS placed in the head, please put embedded JS in the CSS head.

(3), use defer (ie only)

(4), do not call in the embedded JS long-running function, if it must be used, you can use SetTimeout to invoke

JavaScript non-blocking loading concrete way

Place the script at the bottom. \ or put in the head, to ensure that the normal display of the page before JS loading. \

The point of this technique is that no matter where the download is initiated, the file volume is downloaded and run without blocking other page processing processes. Even in the head (except for the HTTP link used to download the file).

19, compare Flash and Ajax which is good?

Advantages of Ajax:

(1), searchable

Ordinary text pages will be more conducive to SEO. Text content is a search engine easy to retrieve, and cumbersome SWF bytecode is a search engine is reluctant to touch. While some large search engines, such as Google, can retrieve content inside the SWF, there is still a lot of trouble.

(2), openness

Flash perennial has been Macromedia to see very dead. including Flex, FMS and other assisted technology has always required expensive installation, maintenance costs. JS, however, has no such trouble. No one is willing to take the risk of legal and copyright.

Cost

Flash development is expensive because flashide and other environments are charged. And Ajax is different. Although there are some inexpensive tools to generate SWF, their work can really not meet the complex needs.

(3), Ease of use

Ajax programs have better ease of use. Because there is a layer of flashplayer agent in the middle, many auxiliary functions cannot be used flexibly by flash. and flash in some aspects have a bad reputation. such as pop-up ads, such as malicious code.

(Http://awflasher.com personally think this probably is caused by the mess XX website)

(4), easy to develop

When people develop complex Ajax and flash applications, they use some advanced development tools. Generally speaking, the development package of Ajax is simpler and easier than flash.

The advantages of Flash:

(1), multimedia processing

Flash has an absolute advantage over HTML in the areas of audio, video and other multimedia. Almost all sites now contain Flash content.

(2), compatibility

Good compatibility: Due to the adoption of the only Flashplayer "agent". People do not have to debug the program in different browsers, like debugging JS.

(3), vector pattern

This is the biggest advantage of Flash, also in this area of SVG, Canvas element and direct can not be compared with flash.

(4), client resource scheduling

Flash makes it easier to invoke external resources outside of the browser. such as cameras, microphones and so on. However, this is normal HTML can not be completed. But this may be a disadvantage (for what?)

Disadvantages of Ajax:

(1), it may destroy the browser's back function

(2), the use of dynamic page update makes it difficult for users to save a specific state to the favorites, but these are relevant methods to solve.

The disadvantages of Flash:

(1), binary format

(2), format private

(3), flash files are often very large, the first time users need to endure longer waiting time

(4)/performance issues

Ajax and Flash each have pros and cons, in the end which is good, depending on your needs

20, please explain the event bubbling mechanism

A, triggering a class of events on an object (such as clicking the onclick event), if this object defines a handler for this event, then this event invokes the handler, and if the event handler is not defined or the event returns true, the event propagates to the object's parent object, From inside to outside until it is processed (all the same events of the parent object will be activated), or it reaches the topmost level of the object, the Document object (some browsers are windows).

B, bubbling events: events are triggered in order from the most specific event target to the least specific event target (Document object)

C, JS bubbling mechanism refers to if an element defines event A, such as the Click event, if the event is triggered, the bubbling event is not blocked, then the event will propagate to the parent element, triggering the parent class's Click function.

Block bubbling time method, compatible with IE (e.canclebubble) and FF (e.stopprogation) function stopbubble (e) {var evt =e| | Window.event;evt.stoppropagation?evt.stoppropagation ():(evt.cancelbubble=true);//Stop bubbling Evt.preventdefault

21. Would you please tell me the difference between split () and join () function?

The former is the form of an array of cuts, which is the conversion of arrays into string join functions to get a batch of strings, and then joins them with a delimiter string to return a string. The Split function takes a string and then disconnects it at the delimiter to return a batch of strings. However, the main difference between the two functions is that join can concatenate multiple strings with any delimiter string, and Split can only use one character delimiter to break the string. To put it simply, if you use split, you are putting a string of characters (based on a delimiter) into a number of elements that are stored in an array. Join is a long string of strings in the array, which can be thought of as the inverse of split.

22. Tell me about your understanding of promise?

ES6 Native provides the Promise object.

The so-called Promise is an object that is used to pass the message of an asynchronous operation. It represents an event in the future that will know the result (usually an asynchronous operation), and this event provides a unified API for further processing. The Promise object has the following two characteristics.

(1), the state of the object is not affected by the outside world. The Promise object represents an asynchronous operation in three states: Pending (in progress), resolved (completed, also known as fulfilled), and rejected (failed). Only the result of an asynchronous operation can determine which state is currently, and no other operation will change that state. This is also the origin of the name Promise, its English meaning is "commitment", that other means can not be changed.

(2), once the state changes, will not change, at any time can get this result. There are only two possible changes to the state of the Promise object: from Pending to resolved and from Pending to rejected. As long as these two situations occur, the state is solidified and will not change, and will keep the result. Even if the change has occurred, you can add a callback function to the Promise object, and you will get the result immediately. This is quite different from the event, which is characterized by the event that if you miss it and then listen to it, you won't get the result.

With the Promise object, the asynchronous operation can be expressed in the process of synchronous operation, avoiding the nested callback functions of layers. In addition, the Promise object provides a unified interface that makes it easier to control asynchronous operations.

Promise also has some drawbacks. First, the Promise cannot be canceled, and once it is newly created it executes immediately and cannot be canceled halfway. Second, if you do not set a callback function, the Promise inside throws an error and does not react externally. Third, when in the Pending state, it is not possible to know the current progress to which stage (just beginning or nearing completion).

23. What is your understanding of the JavaScript garbage collection mechanism?

(1), Mark Clear (Mark and sweep)

This is the most common way of garbage collection in JavaScript, when variables enter the execution environment, such as declaring a variable in a function, the garbage collector marks it as "going into the environment," and when the variable leaves the environment (the function execution ends) marks it as "out of the environment."

The garbage collector adds tags to all variables stored in memory at run time, and then removes variables from the environment and variables referenced by variables in the environment (closures), which are still marked after the completion of the variable that is being deleted.

(2), reference count (reference counting)

Memory leaks often occur in low-version ie because they are garbage collected by reference counting. The policy of reference counting is to keep track of the number of times each value is used, when a variable is declared and a reference type is assigned to the variable, the number of references to this value is 1, and if the value of the variable is changed to another, the value of the reference is reduced by 1, when the number of references to 0 is changed. Note that there is no variable in use, this value cannot be accessed, so you can reclaim the space it occupies so that the garbage collector cleans up the space occupied by a value of 0 references at run time.

Although JavaScript objects are garbage collected through markup cleanup in IE, the BOM and Dom objects recycle garbage by reference counting, which means that circular reference problems occur as long as the BOM and Dom are involved.

24. Say you understand the prototype (prototype)?

JavaScript is a prototype implementation of the language is different from other high-level languages, such as java,c# is determined by the type of inheritance relationship, JavaScript is a dynamic weakly typed language, in short, you can think of JavaScript is all objects, In JavaScript, the prototype is also an object, through the prototype can implement the object's property inheritance, JavaScript object contains a "prototype" internal property, this property corresponds to the object's prototype.

"Prototype" is an intrinsic property of an object and cannot be accessed directly. So to make it easy to see the prototype of an object, the JavaScript engine for Firefox and the Chrome kernel provides a nonstandard accessor of "proto" (the standard object prototype accessor is introduced in the ECMA New standard Object.getprototype ( Object) ").

The primary role of prototypes is to implement inheritance and extension objects.

25. What is the difference between typeof and instanceof?

In JavaScript, judging the type of a variable can be used typeof

(1), numeric type, the value returned by TypeOf is number. For example: typeof (1), the return value is number

(2), String type, the value returned by TypeOf is String. For example, the return value of typeof ("123") is a string.

(3), Boolean type, the value returned by TypeOf is Boolean. For example typeof (True) The return value is Boolean.

(4), object, array, null the value returned is object. For example, typeof (window), typeof (document), typeof (NULL) returns a value of object.

(5), the function type, the value returned is function. For example: typeof (eval), the value returned by typeof (Date) is function.

(6), a non-existent variable, function, or undefined, will return undefined. For example: typeof (ABC), typeof (undefined) return undefined.

In JavaScript, instanceof is used to determine whether an object is constructed by another function.

Storing a value with a reference type when using the TypeOf operator will cause an issue, regardless of what type of object is referenced, and it returns "Object". ECMAScript introduced another Java operator, instanceof, to solve this problem. The instanceof operator is similar to the typeof operator to identify the type of object being processed. Unlike the TypeOf method, the Instanceof method requires the developer to explicitly confirm that the object is of a particular type.

26. Tell me about your understanding of node. js

A, node. js is a JAVASCRIPT runtime environment based on the Google Chrome V8 engine. node. JS uses an event-driven, non-blocking I/O model to make it lightweight and efficient. node. JS's Package Manager, NPM, is the world's largest open source library ecosystem.

B, easy to build responsive, easy to expand network applications, node. JS uses event-driven, non-blocking I/O models to be lightweight and efficient, ideal for data-intensive real-time applications running on distributed devices.

c, simply said that node. JS is running on the server side of JavaScript, is now popular in the language can run simultaneously in the front and back of the program language

27. What is the role of NPM (Package manager)?

NPM is a package management tool that is installed with Nodejs to address many of the issues in Nodejs code deployment, with the following common usage scenarios:

A. Allow users to download third-party packages written by others from the NPM server for local use.

B. Allow users to download and install command-line programs written by others from the NPM server for local use.

C. Allow users to upload their own packages or command-line programs to the NPM server for others to use.

Front End interview Knowledge Point Brocade set JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.