Javascript test question Summary

Source: Internet
Author: User

1. How many data types does JS have? What are operators used to determine the basic data type?

Answer: Number, String, bool, undefined, obejct (null belongs to the object type, so the object is written here)

Typeof

2. List your JS browser compatibility issues.

(1) IE does not support the use of classname to obtain tags. It is not supported by IE.

(2) obtain the scrolltop value of a non-ie window through document. Body. scrolltop

The scrolltopvalue of the retrieved Internet Explorer can pass document.doc umentelement. scrolltop.

(3) Get the subnode through childnodes. ie cannot get the carriage return node, not IE.

(4) innertext is unavailable in Firefox

(5) addeventlistener is not supported by IE and is dedicated to attachevent IE.

(6) The type attribute of the input tag cannot be modified in IE6.

3. Differences between setTimeout () and setinterval () and precautions for using them.

Setinterval (function, time) it executes an expression (Cyclic execution) at a specified time after loading. Generally, it controls the external function.

When setTimeout (function, time) is executed, it is executed once after the specified time delay after loading (only once). Generally, it is placed inside the control function.

Note: (1) the two methods may look very similar and the displayed results will be very similar. However, the biggest difference between the two is that the setTimeout method does not execute the Merge function every X seconds, it executes the function after X seconds after each setTimeout call. This means that if the main part of the function takes 2 seconds to complete, the entire function will be executed every X + 2 seconds. While setinterval is not bound by the function called by itself, it simply repeats the function at a certain time. If you want to execute an action accurately after a fixed interval, you 'd better use setinterval. If you don't want to interfere with each other due to continuous calls, in particular, each function call requires heavy computing and a long processing time, so it is best to use setTimeout.

(2) Pay attention to timely timer cleaning

(3) setTimeout (Alert (this), 20)/setinterval (Alert (this), 20) all point to the window

(4) parameters cannot be directly transmitted.

4. convert a string to an integer, and convert a string to an integer.

(1) parseint (), number ();

(2) tostring (); string (); "";

5. How do you avoid JS naming conflicts during team development?

(1) closure (function (){})

(2) namespace

(3) naming conventions can be specified before development, prefix the functions developed by different developers before the Function

6. Briefly describe the common methods for binding events. What are their characteristics?

(1) bind tags;

(2) element. On + type = func;

(3) attachevent ("On" + type, func );

(4) addeventlistener (type, func, false); execute the bubble stage.

Addeventlistener (type, func, true); capture

7.

FunctionTest () {alert (This);} Test ();VaRO = ['A']; O. Test= Test3 =Function() {Alert (This);} O. Test (); test3 ();

What are the pop-up items? Why?

The first window is displayed. This points to window in the function,

The second bullet is a. This In the method points to the object.

The third window is displayed. test3 is a function;

8.

VaRA = 1;FunctionTest () {++; Alert ();VaRA = 1; Alert (a);} test ();

What is the result? Why?
When Nan and a are found in test (), if var A is not declared before, a will automatically become var A; but no value is assigned, so it is undefined, when executing a ++, it will become Nan, not a valid value;
The second bullet 1, because the declared variable A = 1; so the pop-up 1;

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.