JavaScript Interview Topics

Source: Internet
Author: User

1. What data types are returned by JavaScript typeof

Returns the six-type number string object function undefined

Example:typeof 37=== ' number ' typeof "str" = = = ' String '

typeof true=== ' Boolean ' ; typeof undefined=== ' undefined '

typeof {a:1}=== ' object ' ; typeof function () {}=== ' function '

2. examples of 3 coercion type conversions and 2 Implicit type conversions ?

Mandatory Type: (parseint,parsefloat,number)

Boolean (value): Converts the value to a Boolean type; number (value): Converts the value to a digit (integer or floating-point)

String (value): Converts the value to a string.

implicit type: (= = = = = = =)

    1. the difference between split () ,join ()

The former is the form of an array of cuts, the latter is the conversion of arrays into strings

The Split () string method joins strings with delimiters to return a set of string numbers

The join () array method places all elements of an array into a string.

To put it simply, if you use split (), you are putting a string of strings (based on a delimiter) into a number of elements that are stored in an array.

join is to concatenate the strings in the array into a long string, which can generally be thought of as the inverse of split.

4. Array method pop () push () unshift () Shift ()

  push () appends an element like an array trailing   pop () tail delete unshift () head add     shift () head delete    except    

Example var Array=["A" ,"J"];
Array. Push ("L"); //Tail increase
Array. Pop (); //Trailing Delete
Array. Unshift ("Q") //Header Append
Array. Shift () //head Delete
Console. log (array) //The element inside the last array is still the original

    1. What is the difference between an event binding and an ordinary event?

difference The usual method of adding events does not support adding multiple events, and the bottom event overwrites the above,

The event binding (AddEventListener) method adds more than one event can add.

Example

var btn = document.getElementById ("btn");

Btn.onclick = function () {alert (' normal event 1 ');//Do not execute}

Btn.onclick = function () {alert (' normal event 2 ');//Popup}

Add two events using the normal method above, and add two events with event bindings below. Btn.addeventlistener (' click ', function () {alert (' event binding 1 ');//popup},false); Btn.addeventlistener (' click ', function () {alert (' Event binding 2 ');//popup},false);

    1. the difference between IE and DOM Event streams

IE uses the bubbling event Netscape to use the captured event Dom to capture the post-bubble event first

1. The order of execution is different,

Bubbling Event Model: button->div->body (ie event stream)
Capture-type event model: Body->div->button (Netscape event Stream)

DOM Event Model: Body->div->button->button->div->body (first captured after bubbling)
2. Different parameters

IE uses:
[Object].attachevent ("Name_of_event_handler", Fnhandler); Binding functions
[Object].detachevent ("Name_of_event_handler", Fnhandler); Remove bindings
DOM uses:
[Object].addeventlistener ("Name_of_event", Fnhandler, Bcapture); Binding functions
[Object].removeeventlistener ("Name_of_event", Fnhandler, Bcapture); Remove bindings
3. Event not added on

DOM events are addeventlistener by adding elements to listen for an event, the first argument is that the event name does not start with an on (onclick to write click)
4.this pointing problem

The This is the element that is no longer a previously registered event when the Attachevent registered handler function is invoked under IE, this is the window

This refers to the element of a previously registered event when the DOM is called by the AddEventListener registered handler function .

7. what is the compatibility of IE and standard ?

Var ev = EV | | Window.event
Document.documentElement.clientWidth | | Document.body.clientWidth
Var target = ev.srcelement| | Ev.target

8. the difference between call and apply

Call, the role of apply is to borrow someone else's way to invoke, just like calling their own.

Call Method:
Syntax:call ([thisobj[,arg1[, arg2[, [,. ArgN]]])

is a direct parameter list, mainly used in the JS object Each method calls each other, so that the current this instance pointer is consistent, or in special cases need to change the this pointer. If the Thisobj parameter is not provided, then the Global object is used as the thisobj.

Apply method:
Syntax:apply ([Thisobj[,argarray]])

Apply: can have up to two parameters-new this object and an array

To put it simply,the apply and call functions are just the same as the parameter list passed in: For example, Func.call (FUNC1,VAR1,VAR2,VAR3), the corresponding apply is written as:

Func.apply (Func1,[var1,var2,var3])

9. B method of inheriting a

definitionA and extend its prototype properties
functiona(){

}
a.prototype.myname="Cat";
a.prototype.Myage= 18;
a.prototype. study=function() {
Alert (111)
};

varm=Newa();
m. study ();
Document. Write (m.myname)

functionb() {

};
b Method of inheriting a
b.prototype=a.prototype;
varM1=Newb();
M1. study ();
Document. Write (M1.Myage)

    1. How to block event bubbling and default events

Block Default Events

1. in Javescript, return flase can block the default event, but must be added to the OnMouseDown event,the down is done, and then return Flase.

2. in the Custom function addevent, return flase will fail, use the event object to block. Ev.preventdefault ();//block default events.

3,in the low version of ie these are not so, need to call Obj.setcapture&&obj.setcapture () in the OnMouseMove event ; and clear Obj.releasecapture&&obj.releasecapture () in the onmouseup event ;

Blocking Event Bubbling:

1 . When a child's event is triggered, the event of its parent is also triggered.

2. Bubbles are not related to where they appear in the page, as long as the two are parent-child relationships in the HTML structure, event bubbling exists.

3. Block event bubbling must be added to the child's body. Blocked by the event object. Ev.cancelbubble=true;

JavaScript Interview Topics

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.