Front End Question Summary-javascript

Source: Internet
Author: User

1. How can I achieve communication between multiple tabs in the browser?

      call Localstorge, cookies and other local storage methods

2.JavaScript prototypes, prototype chains

      Although you can access and modify the values saved in the prototype through an object instance, you cannot override the values in the prototype through an object instance. Doing so would be equivalent to creating an attribute on the instance.

The basic data type of 3.js.

number,string,boolean,object,undefined

4.["1", "2", "3"].map (parseint) What's the answer?

[1, Nan, Nan] because parseint requires two parameters (Val, radix), where radix represents the cardinality used for parsing. Map passed 3 (element, index, array), the corresponding radix is not valid cause parsing failure.

5.This objects

    • This is a keyword of JS, and the value of this will change as the function is used in different situations.
    • But there is a general principle that this refers to the object that invokes the function.
    • This is the general case: global object. As a method call, then this refers to this object

6. What is the event? What is the difference between IE and Firefox's event mechanism? How do I stop bubbling?

  1. We have an action on the Web page (some actions correspond to multiple events). For example, when we click on a button, an event is generated. is a behavior that can be detected by JavaScript.
  2. Event handling mechanism: IE is event bubbling, Firefox is event capture;
  3. Function: Stop event bubbling
    function Stopbubble (e) {
    If an event object is provided, this is a non-IE browser
    if (e && e.stoppropagation)
    So it supports the Stoppropagation () method
    E.stoppropagation ();
    Else
    Otherwise, we need to use IE to cancel the event bubbling
    Window.event.cancelBubble = true;
    }

7. What is a closure (closure) and why use it?

    • Creating a function inside a function and using a variable inside the function is the closure
    • Closure of variables: the use of closures, if a callback is used in the constructor, and this can be called internally by the closure
    • var = this;
    • Closure of the function:
    • can return functions
    • Using closures will raise the variable level and will not be cleared automatically after the function ends, to eliminate the memory overflow manually

8. "Use strict"; What do you mean? What are the advantages and disadvantages of using it?

Strict mode, make the writing specification, but the browser strict degree is different, node recommended to use, front-end is not recommended

9. How can I tell if an object belongs to a class?

Using instanceof

What exactly did the 10.new operator do?

    • 1. Create an empty object, and the this variable references the object, and also inherits the prototype of the function.
    •    var obj  = {};    obj.__proto__ = Base.prototype;
    • 2, properties and methods are added to the object referenced by this.
    •    Base.call (obj);
    • 3. The newly created object is referenced by this and the last implicitly returns this.

11.Javascript, there is a function, the execution when the object lookup, never go to find the prototype, this function is?

hasOwnProperty

12.JSON

is a lightweight data interchange format. It is based on a subset of JavaScript. Simple data format, easy to read and write, low bandwidth consumption

What are the modes of 13.js lazy loading?

    • Defer and Async
    • Dynamically create DOM mode (most used)
    • Asynchronous loading JS (amd,cmd) On demand

14. Modular How to do

Execute functions immediately, without exposing private members

15.amd-require.js

See here

The difference between 16.documen.write and innerHTML

    • Document.Write can only redraw the entire page
    • innerHTML can redraw part of a page

The difference between 17.call () and apply ()

    • Call accepts multiple parameters
    • Apply accepts two parameters, the second parameter is an array
    • When a function is called, a different this object can be assigned. This refers to the current object, which is the first parameter of the call method.

18. Optimization for Query

      1. Class-based selectivity has a high overhead relative to the ID selector because all DOM elements need to be traversed.
      2. Dom, which is frequently manipulated, is cached and then manipulated. Or a chain call with jquery is better.
   var str=$ ("a"). attr ("href");
    1. for (var i = size, length = arr.length; i < length; i++) {} than for (var i = size; i < arr.length; i++) {} good

Scope and variable declaration promotion in 19.JavaScript

    1. Within a function is scope
    2. In-function variable declaration var uses the previous-level variable, and then queries up, and if not, the variable is a global variable
    3. This is the global variable used by the SetTimeout method
    4. Raising a variable declared under a function in JavaScript to the beginning of a function is a variable declaration promotion, the most common of which is the function

20. Memory leaks

    • Eliminate declared variables (do not use delete)
    •    var o = {x:1};    o = null;
    • Global variables are not recycled, try not to use
    • If the data being used is cached locally, be sure to clean up the cache or use the aging mechanism to avoid storing large amounts of data that are not reused.
    • Be sure to unbind event listeners that are no longer needed, especially those that are bound by the DOM objects that are about to be destroyed.
    • Closures can cause memory leaks if not cleaned up in time

21. How to write high-performance JavaScript

    • Note Memory leaks
    • Readability, inheritance models and maintainability are more important than performance
    • Yahoo 14 rule: http://segmentfault.com/blog/trigkit4/1190000000656717
      1. Enable gzip compression
      2. Reduce the number of HTTP requests: CSS Sprites, JS, CSS source compression, picture size control appropriate; web Gzip,cdn hosting, data caching, image server.
      3. Front-end template js+ data to reduce bandwidth waste due to HTML tags, front end with variables to save AJAX request results, each operation local variable, no request, reduce the number of requests
      4. Use innerHTML instead of DOM operations to reduce DOM operation times and optimize JavaScript performance.
      5. When you need to set a lot of styles, set classname instead of manipulating the style directly.
      6. Use fewer global variables and cache DOM nodes to find results. Reduce IO read operations.
      7. Avoid using CSS expressions
      8. Picture preloading, placing the style sheet at the top, and placing the script at the bottom with a timestamp.
      9. Avoid using table,table in the main layout of the page to wait for the content to be fully downloaded before it is displayed, which is slower than the div+css layout.

22. How can I tell if the current script is running in a browser or node environment?

The current script is not running in the browser by judging whether the global object is window or not window

Front End Question Summary-javascript

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.