In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what are the classic interview questions about the front end of Javascript. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. What data types are returned by the typeof of JavaScript?
Analysis:
This question tests the basic skills of JS, so as long as you know the typeof operator, it is not too difficult. In the specific answer, and then combined with the theoretical knowledge and the actual situation in the coding process to answer. In addition, considering the rigor of the interview, the new types in ES2015 are also incorporated into the reply.
Suggested reply:
First of all, there are two big data types in JavaScript:
Basic type
Reference type
Basic types include: Number, String, Boolean, Null, Undefined, Symbol (new type in this bit ES2015)
Reference types include: the Object typeof operator returns type information as a string, and it is important to note that the type returned by typeof is slightly different from the type defined by JavaScript. Typeof returns seven possible values: "number", "string", "boolean", "object", "symbol", "function" and "undefined".
Please write the following code operation result:
Alert (typeof null); alert (typeof undefined); alert (typeof NaN); alert (NaN = = undefined); alert (NaN = = NaN); var str = "123abc"; alert (typeof str++); alert (str)
Analysis:
This question is closely related to "question one". When "question one" is answered, it will once again strengthen the basic skills of operators and data types.
Suggested reply:
The main purpose of this question is to examine the types of typeof judgment values, and the output results are as follows:
Alert (typeof null); / / objectalert (typeof undefined); / / undefinedalert (typeof NaN); / / numberalert (NaN = = undefined); / / falsealert (NaN = = NaN); / / falsevar str = "123abc"; alert (typeof str++); / / numberalert (str); / / NaN
3. Give examples of at least 3 forced type conversions and 2 implicit type conversions?
Analysis:
Type conversion may sound a bit broad, but this question clearly gives the scope of the answer.
Suggested reply:
1. Cast: explicitly call built-in functions to force the conversion of values from one type to another. Forced type conversions mainly include: Boolean, Number, String, parseInt, parseFloat
two。 Implicit type conversion: when using arithmetic operators, the data types on both sides of the operator can be arbitrary, for example, a string can be added to a number. The reason why operations can be done between different data types is that the JavaScript engine quietly converts them before the operation. The main implicit type conversions are: +, -, =,!
4. What are the event flow models of JavaScript?
Suggested reply:
The event flow describes the order in which events are received from the page. The DOM structure is a tree structure. When an element in the page triggers an event, the event will start from the top-most window object and propagate down to the target element, and the ancestor node of the path will trigger the corresponding event. If the event of the current node is bound to the event handler, the function will be executed when the event reaches the target element and the binding function (if any) is executed The event is propagated up to the window element, and the ancestor node of the path triggers the corresponding event (if the event handler is bound)
The event flow consists of three phases:
Event capture phase
Be in the target stage
Event bubbling stage
Event capture phase: the event is triggered by the top-level object and then propagates down step by step to the target element
In the target phase: on the element that binds the event
Event bubbling phase: events are first received by specific elements, and then propagated step by step up to non-specific elements
5. What are the BOM objects and list the window objects?
Suggested reply:
Window object, which is the top-level object of JS, and other BOM objects are properties of window object.
Document object, document object
Location object, browser current URL information
Navigator object, browser itself information
Screen object, client screen information
History object, browser access history information
6. Please briefly describe AJAX and its basic steps.
Analysis:
For this kind of pure concept question, it is recommended to write the encapsulation process of the native AJAX function again before the interview, and it must be memorized on the basis of understanding in order to have a good performance in the interview.
Suggested reply:
A brief introduction to AJAX:AJAX, namely "Asynchronous Javascript And XML" (Asynchronous JavaScript and XML), refers to a web page development technology for creating interactive web applications. By exchanging a small amount of data with the server in the background, AJAX can update web pages asynchronously. This means that some part of the page can be updated without reloading the entire page.
The basic steps of AJAX:
Initialize the ajax object
Connection address, preparing data
Send a request
Receive data (receiving, not yet completed)
Completion of receiving data
/ / initialize the ajax object var xhr = xhr = new XMLHttpRequest (); / / connect the address to prepare the data xhr.open ("method", "address", whether it is asynchronous); / / receive the event triggered by the completion of the data xhr.onload = function () {} / / send the data xhr.send ()
7. What does the HTTP status message 200 302 304 403 404 500 indicate respectively?
Analysis:
"memorizing with understanding" is the best magic weapon to deal with conceptual problems. in addition, it is also beneficial to look at the extended knowledge points.
Suggested reply:
200: the request was successful, and the desired response header or data body of the request will be returned with this response.
The requested resources temporarily respond to requests from different URI. Because such redirects are temporary, the client should continue to send future requests to the original address. This response is cacheable only if specified in Cache-Control or Expires.
304If the client sends a conditional GET request and the request is allowed, and the content of the document (since the last access or according to the requested condition) has not changed, the server should return this status code. The 304 response prohibits the inclusion of the message body, so it always ends with the first blank line after the message header.
403: the server understands the request but refuses to execute it.
404: the request failed and the desired resource was not found on the server.
500: the server encountered an unexpected condition that prevented it from completing the processing of the request. In general, this problem occurs when there is an error in the server-side source code.
8. The difference between synchronous and asynchronous?
Analysis:
It's a concept again.
Suggested reply:
First of all, synchronous asynchronism is not related to blocking and non-blocking. Synchronous and asynchronous is mainly how to deal with, or focus on, a message communication mechanism after things are done.
In the case of synchronization, it is up to the messenger to wait for the message to be triggered.
In the case of asynchronism, the trigger mechanism is used to notify the messenger.
For example: for example, in class, you ask the teacher a question, which may take a little time to think about, at this time the teacher may:
Think, think... Oh, all right, here's the answer.
This question will take a little time, you do something else first, and when I think about it, I will come to you.
The first is synchronous, and the second is asynchronous. So synchronous and asynchronous can be said to the requested party, what method the requested party uses to inform the processing result.
Blocking is non-blocking, mainly for the requester.
Blocking: make a request to wait for the result to return, and then deal with the rest
Non-blocking: make a request without waiting for the result to return, you can go on to do the next thing
For example, it is the previous example:
When the teacher is using synchronous thinking, you can quietly wait for the teacher to give an answer, or you can wait for the teacher's answer while doing your own things. of course, you need to pay attention to whether the teacher has made up his mind at this time. Polling is needed in the program. "(" ε ")
The teacher uses an asynchronous way, at this time the teacher tells you that you can do something else first, and I'll let you know when it's okay, then you can do something else, and then you can monitor the event, of course, you can also be very axial, I won't do anything else! I will always wait for the incident that the teacher has made up his mind to happen.
So synchronization can be blocking or non-blocking, and so can asynchrony.
9. The difference between GET and POST, when to use POST?
Analysis:
The probability of a concept question such as data interaction being asked during an interview also reflects its practical value in the job. So there's nothing else. Study hard and recite well!
Suggested reply:
The difference between GET and POST:
GET: generally used to query data and use URL to pass parameters. Because the browser has a limit on the length of the address bar, there is a limit on the amount of information sent using get. At the same time, the browser will record (history, cache) the information of the requested address, including the data behind the address. Get can only send data in normal format (URL encoded format).
POST: generally used to send data to the server, there is theoretically no limit on the size of the data sent. The browser will cache the record address, but will not record the data submitted by post. Post can send strings in plain text, URL encoding format and binary format in a variety of forms.
Use the POST request in the following cases:
A request for submission (similar to semantics, with get for request and post for submission)
Send private class data (username, password) (because of the browser cache record feature)
Send large amounts of data to the server (differences in data size limits)
When uploading a picture of a file (data type difference)
What are the limitations of AJAX?
Suggested reply:
AJAX does not support browser back buttons.
The security issue AJAX exposes the details of interaction with the server.
The support for search engines is weak. Will not execute your JS script, will only manipulate your web page source code
There are certain restrictions on cross-domain requests. Solution: jsonp
11. What exactly does the new operator do?
Analysis:
The concept of principle.
Suggested reply:
When the constructor is called using the new operator, the function actually goes through the following steps:
Create a new object
Point the context (scope) object this in the function to it
Execute the code to add properties or methods to the new object through this
Return object
12. The difference between null and undefined?
Analysis:
Classic concept questions.
Suggested reply:
Null: null indicates a null value, which is 0 when converted to a numeric value
Undefined:undefined stands for "missing value", which means there should be a value here, but it hasn't been defined yet.
Variables are declared, but when they are not assigned, they are equal to undefined.
Object has no property assigned to it, and the value of this property is undefined.
When the function does not return a value, it returns undefined by default.
13. JavaScript prototype, prototype chain? What are the characteristics?
Suggested reply:
JavaScript prototype: every time a function is created, the function has an attribute of prototype, and its value is an object. The purpose of this object is that when you use a function to create an instance, the instances will share the properties and methods on the prototype.
Prototype chain: in JavaScript, each object has an internal link (proto) to its prototype object. This prototype object also has its own prototype until the prototype of an object is null (that is, there is no prototype pointing to it). This level-by-level chain structure is called prototype chain. When looking for a property of an object, JavaScript iterates up the prototype chain until it finds a property with a given name; when the lookup reaches the top of the prototype chain (Object.prototype) and still does not find the specified property, it returns undefined.
14. To realize the disordering of the array
Analysis:
This question examines the sort () method of the array. Because it is out of order, we also need to use Math.random () to generate random numbers and disrupt the sorting rule.
Suggested reply:
Before you write the code, introduce the principle of the implementation before you start writing the code:
Var a = [1,2,3,4,5,6,7,8,9,10]; var sign = 1; a.sort (function (a, b) {return Math.random ()-0.5})
15. Implement a function clone (), which can copy the values of five main data types in JavaScript (including Number, String, Object, Array, Boolean).
Analysis:
This question examines the following knowledge points:
Use typeof to determine the worthwhile type
Using toString to distinguish between arrays and objects
The use of recursive functions
Suggested reply:
Function clone (obj) {/ / determines that it is an object, then copies if in a loop (typeof obj = = 'object' & & typeof obj! =' null') {/ / distinguishes between an array and an object, and creates an empty array or object var o = Object.prototype.toString.call (obj) .slice (8,-1) = = "Array"? []: {} For (var k in obj) {/ / if the value corresponding to the attribute is an object, then recursively copy if (typeof obj = = 'object' & & typeof obj! =' null') {o [k] = clone (obj [k])} else {o [k] = obj [k];} else {/ / is not an object and returns the value directly to return obj;} return o } this is the end of the article on "what are the classic interview questions for the front end of Javascript?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.