In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the title of the interview JavaScript? aiming at this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
1. How do I add, remove, move, copy, create, and find nodes?
1) create a new node
CreateDocumentFragment () / / create a DOM fragment
CreateElement () / / create a concrete element
CreateTextNode () / / create a text node
2) add, remove, replace, insert
AppendChild () / / add
RemoveChild () / / remove
ReplaceChild () / / replace
InsertBefore () / / insert
3) find
GetElementsByTagName () / / by tag name
GetElementsByName () / / pass the value of the Name attribute of the element
GetElementById () / / through element Id, uniqueness
2. Implement a function clone, which can copy the values of five main data types in JavaScript (including Number, String, Object, Array, Boolean).
/ * *
* object cloning
* basic data types and objects are supported
* Recursive method
* /
Functionclone (obj) {
Varo
Switch (typeof obj) {
Case "undefined":
Break
Case "string":
O = obj + ""
Break
Case "number":
O = obj-0
Break
Case "boolean":
O = obj
Break
Case "object": / / object is divided into two case objects (Object) or arrays (Array)
If (obj = null) {
O = null
} else {
If (Object.prototype.toString.call (obj) .slice (8,-1) = = "Array") {
O = []
For (vari = 0 * * I obj.length;i++) {
O.push (clone (obj [I]))
}
} else {
O = {}
For (varkinobj) {
O [k] = clone (OBJ [k])
}
}
}
Break
Default:
O = obj
Break
}
Returno
}
3. How to eliminate duplicate elements in an array?
/ / method 1:
Vararr1 = [1, 2, 2, 2, 3, 3, 3, 4, 5, and 6]
Arr2 = []
For (vari = 0 Len = arr1.length;i < len;i++) {
If (arr2.indexOf (ARR1 [I]) < 0) {
Arr2.push (ARR1 [I])
}
}
[xss_clean] (arr2); / / 1Jing 2Jing 3jue 4JI 5jue 6
4. Do you want to drag a node on the page? How to do it? (use native JS).
5. What is a pseudo array in Javascript? How to convert a pseudo array to a standard array?
Pseudo arrays (class arrays): you cannot call array methods directly or expect any special behavior of the length property, but you can still traverse methods on real arrays to traverse them. Typically, the argument parameters of the function, and things like calling getElementsByTagName,document.childNodes, all return NodeList objects that belong to pseudo arrays. You can use Array.prototype.slice.call (fakeArray) to convert an array into a real Array object.
Functionlog () {
Varargs = Array.prototype.slice.call (arguments)
/ / in order to use the unshift array method, convert argument to a real array
Args.unshift ('(app)')
Console.log.apply (console,args)
}
6. The role of callee and caller in Javascript?
Caller returns a reference to a function that calls the current function
Callee returns the function function being executed, that is, the body of the specified function object.
7. Please describe the difference between cookies,sessionStorage and localStorage
SessionStorage is used to store data in a session (session) locally, which is accessible only to pages in the same session and is destroyed when the session ends. So sessionStorage is not persistent local storage, just session-level storage. On the other hand, localStorage is used for persistent local storage, and the data will never expire unless it is actively deleted.
The difference between web storage and cookie
The concept of web Storage is similar to that of cookie, except that it is designed for greater storage capacity. The size of Cookie is limited, and every time you request a new page, Cookie is sent, which virtually wastes bandwidth. In addition, cookie also needs to specify a scope and cannot be called across domains.
In addition, web Storage has methods such as setItem,getItem,removeItem,clear, unlike cookie, which requires front-end developers to encapsulate setCookie,getCookie. But Cookie is also impossible or missing: the role of Cookie is to interact with the server as part of the HTTP specification, while web Storage is simply created to "store" data locally.
8. Quick sort of handwritten array
For a detailed description of the fast sorting algorithm, you can refer to teacher Ruan Yifeng's article quick sorting.
The idea of "quick sort" is simple, and the whole sorting process takes only three steps:
(1) in the dataset, select an element as the "pivot".
(2) all elements smaller than the "base" are moved to the left of the "base"; all elements greater than the "base" are moved to the right of the "base".
(3) repeat the first and second steps for the left and right subsets of the benchmark until there is only one element left in all the subsets.
9. Count the number of letters or the maximum number of letters in the string "aaaabbbccccddfgh".
Varstr = "aaaabbbccccddfgh"
Varobj = {}
For (vari=0;istr.length;i++) {
Varv = str.charAt (I)
If (OBJ [v] & OBJ [v] .value = = v) {
Obj [v] .count = + + obj [v] .count
} else {
Obj [v] = {}
OBJ [v] .count = 1
Obj [v] .value = v
}
}
For (key inobj) {
[xss_clean] (obj [key] .value +'='+ obj [key] .count +'); / / axi4bao3ced4dong2fus1g1ht1
}
10. Write a function to clear the spaces before and after the string. (compatible with all browsers)
Functiontrim (str) {
If (str & typeof str = "string") {
Returnstr.replace (/ (^ s*)) | (s*) $/ g, ""); / / remove whitespace characters
}
}
The answer to the question about the interview JavaScript is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.