2020 front-end JavaScript face questions / finishing wrong questions

1. Introduction of basic data types JavaScript

Number, String, Boolean, Null, Undefined Object is JavaScript parent objects all objects in the
data encapsulator class object: Object, Array, Boolean, Number, and String
other objects: Function, Arguments, Math, Date , RegExp, Error
New Type: Symbol

2.eval is doing what?

Its function is to parse the string corresponding to the code and run JS; should avoid the eval, unsafe, huge performance (2 times, once resolved into js statements, execution time).
JSON string into a JSON object can be used when eval, var obj = eval ( ' (' + str + ')');

3.Javascript, there is a function, when the object is to find the time to perform, never to find the prototype, this function is?

hasOwnProperty
javaScript in hasOwnProperty function is to return a Boolean value indicating whether an object has the property specified name. This method does not check the object's prototype chain has a property; the property must be a member of the object itself.
Usage: object.hasOwnProperty (proName) where the parameter object is mandatory. Examples of an object.
proName is Required. A string value of the attribute name. If the object
having the specified attribute name, then the function returns true JavaScript in hasOwnProperty method, otherwise returns false.

4.js lazy loading options?

defer and async, dynamically created DOM mode (most used), on-demand asynchronous loading js

5. How to determine the current script running in the browser or node environment?

? this === window 'browser': 'node';
by Global determine whether the object is a window, if not a window, the current script is not running in the browser

6. include three kinds of casts and two kinds of implicit type conversion?

Forced (parseInt (), parseFloat () , Number ())
implicit (==,! =)

Difference 7.split (), join () of

The former is cut in the form of an array, which is the array into a string

8. Method Array pop () push () unshift () shift () map () filter ()

push () tail add pop () tail deletion
unshift () to add the head shift () head delete
map (): traverse the elements in the array and returns a new array (containing data callback function returns)
filter (): iterate the elements and returns a new array (comprising a callback function returns true element)

9. How to stop the event from bubbling events and default behavior

//阻止事件冒泡

if(typeof ev.stopPropagation=='function') {  //标准的

    ev.stopPropagation();

} else { //非标准IE

    window.event.cancelBubble = true;

}

//阻止事件默认行为
return false
window.onload 和document ready的区别
window.onload 是在dom文档树加载完和所有文件加载完之后执行一个函数 document.ready原生中
没有这个方法,jquery中有 $().ready(function),在dom文档树加 载完之后执行一个函数
(注意,这里面的文档树加载完不代表全部文件加载完)。
$(document).ready要比window.onload先执行
window.onload只能出来一次,$(document).ready可以出现多次

10. "==" and "===" different

The former will be automatically converted to the type of
the latter will not

11. When a DOM node is clicked, we want to be able to perform a function, how should we do?

Direct binding events in the DOM: <div οnclick=”test()”></div>
by binding in the JS onclick: xxx.onclick = test
by adding binding event:addEventListener(xxx, ‘click’, test)

What are the event flow model 12.Javascript?

"Event bubbling": Event began to accept the most specific elements, and then progressively spread upward
"event capture": an event is received by the least specific node first, then progressively down until the most specific
"DOM event flow ": three stages: event capture, target stage, event bubbling

13. The interception of the string abcdefg efg

alert('abcdefg'.substring(4));

14. The string reversal, as will be '12345678' to '87654321'

//思路:先将字符串转换为数组 split(),
利用数组的反序函数 reverse()颠倒数组,再利用 jion() 转换为字符串

var str = '12345678';
str = str.split('').reverse().join('');

15. What action will cause a memory leak?

A memory leak means that an object no longer has any need or later it's still there in your.

Garbage collector periodically scans the object, and calculates the number of references to other objects of each object.
If an object reference number is 0 (no other object reference through the object), or the only reference to the object is circular, then the object's memory can be recovered.

  1. The first parameter of setTimeout use string instead of a function, it will lead to memory leaks.
  2. Closure
  3. Console log
  4. Cycle (when the two objects to one another and each other to retain a reference, will produce a cycle)

16.typeof operator returns the value in a data type is inconsistent with javascript, is it? How to determine the array is not it?

Array,Array.isArray(data)

17.window.location.search () returns what?

http://localhost:8080/xxx?ver=1.0&id=123

Return value:? Ver = 1.0 & id = timlq is part after the question mark

18.window.location.reload () action?

Refresh the current page.

Garbage collection mechanism in 19.javascript?

In Javascript, if an object is no longer referenced, the object will be recovered GC. If two objects refer to each other, and no longer
be referenced by a third party, then the two objects reference each other will be recovered. Because a function is referenced b, b has been cited outside a c, which is the reason why the function can not be executed after a recovery.

20. Description of the difference between the disabled and readonly

And Disabled ReadOnly role is to enable users to change the content without form fields but both still there are some differences:.
1, Readonly only for input (text / password) and textarea effective, but disabled for all forms of
valid elements, including select, radio, checkbox, button and so on.
2, in the form elements using the disabled, we will form with the POST or GET submission, then this
value elements will not be passed out, and the value will pass out readonly

21. implemented using JavaScript ascending order. Data for the 23,45,18,37,92,13,24

// ascending algorithm

function sort(arr){

    for (var i = 0; i <arr.length; i++) {

        for (var j = 0; j <arr.length-i; j++) {

            if(arr[j]>arr[j+1]){

                var c=arr[j];//交换两个变量的位置

                arr[j]=arr[j+1];

                arr[j+1]=c;

            }

        };

    };

    return arr.toString();

}

console.log(sort([23,45,18,37,92,13,24]));

22. Please tell three ways to reduce page load time

1, compression css, js file

2. Consolidated js, css files, reducing http requests

3, external js, css files on the bottom

4, dom reduction operation, as with variable substitution operations unnecessary dom

23. The variable lift

function sayHi(){
		console.log(name);
		console.log(age);
		var name = "Tom";
		let age = 18;
	}

	sayHi();
  • A: Tom 和 undefined
  • B: Tom 和 ReferenceError
  • C: ReferenceError 和 18
  • D: undefined 和 ReferenceError

In the function, we first use the var keyword to declare a variable name. This means that the variable will be promoted at the creation stage (JavaScript creates a stage for their allocated memory space create a variable), the default value is undefined, until we actually execute the line to use the variable.
We do not have to name variable assignment, so it remains undefined value of.
Variable use the let keyword (and const) variable declared there will increase, but with different var initialization has not been promoted. Before we declare (initialization) them, they are not accessible. This is called "temporary dead zone." When we try to access the variable before you declare a variable, JavaScript will throw a ReferenceError.

24.setTimeout function

for (var i = 0; i < 3; i++) {
	  setTimeout(() => console.log(i), 1);
	}

	for (let i = 0; i < 3; i++) {
	  setTimeout(() => console.log(i), 1);
	}
  • A: 0 1 2 0 1 2 and
  • B: 0 1 2 3 3 3 and
  • C: 3 3 3 0 1 2 and
  • Answer: C

Because of the asynchronous execution mechanism in JavaScript, when setTimeout function actually been executed, the cycle has been completed.
Since the first loop variable i is declared using the var keyword, so the value is global. During the cycle, each time we use the unary + 1 will increase the value of i.
Therefore, in the first example, when calling setTimeout function, I have been assigned to 3.
In the second cycle, the let keyword used to declare variables i: let variables (and const) keyword is declared (block anything between {a}) having a block scope. During each iteration, I will be created as a new value, and each value is present in the block-level scope within the loop.

25. The array definition (wrong title)

var a = [] array to create a length of 0, a [5] = 4, the array length is automatically extended to 6, no assignment elements are undefined.

26. The internal variables with the same name as a global variable when (the wrong title)

The external variable internal variable cover

27. The method of statement about the function block (wrong question)

if(x){var foo =function(){}}

Have var

28. For transmitting a message to the sub-scope

$emit() 向上冒泡
$broadcast() 是向下传播事件

29. How do you prevent the browser's default behavior

Two ways:

window.event.returnValue=false;
event.preventDefault();

30. Arithmetic

JavaScript defined var a = "40", var b = 7, a% b is performed will be (5).

We will do during an arithmetic operation, the + sign, digital implicitly converted to a string. The remaining operation symbol string is converted into a digital implicitly.

31.w3c develop javascript standard event model (wrong title)

Event capture -> Event Processing -> event bubbling

32.JavaScript resolution order

After following code execution, num values ​​are?

var foo=function(x,y){
return x-y;
}
function foo(x,y){
return x+y;
}
var num=foo(1,2);
答案:-1

33. Which of the following is not a JavaScript data types:

Integer

Int Integer is a wrapper class. javascript is a weakly typed language, not necessary to specify a particular data type definition of variables. data are in javascript type Undefined, Null, Boolean, Number. belong to these basic types. Object,
Array,
Function belongs to the reference type. Some special string type, having a variable size because the string, it is clear that it can not be stored directly in variable with a fixed size. For efficiency reasons, we only want to copy JS reference to the string, rather than the content of the string. On the other hand, the basic types and strings are similar in many respects the performance of, and the fact that the string is immutable (i.e., not changing the content of a string value), the behavior can be seen with the string substantially similar type immutable reference type

34. described in JavaScript, call object attribute, for example: call attribute object obj arr

obj["arr"]
obj["a"+"r"+"r"]
obj.arr

In point mode or parenthetically

35. How to determine whether the object is a js Array, arr as an object to determine which method is the most accurate?

Here Insert Picture Description

typeof(arr) 返回的是 Object
instanceof 在跨 frame 对象构建的场景下会失效
arr.toString 没有这种用法,正确的用法是 arr.toString() 返回的是数组的内容

From the string 36. const str = 'qwbewrbbeqqbbbweebbbbqee'; results can be obtained in the [ "b", "bb", "bbb", "bbbb"] The following statement is wrong?

Moderation: Error
Here Insert Picture Description

+ Means at least one b
* b represents may not occur, can also occur one or more times
{n, m} represents the minimum occurs n times b, appears at most m times b

/b+/g    //匹配前面的子表达式一次或多次,有一个或多个b
 /b*/g    //匹配前面的子表达式零次或多次,结果不止数组中那么多
 /b{1,4}/g   //匹配1-4个b 
 /b{1,5}/g    //匹配1-5个b

37. Which of the following is not the way to change the scope chain?

Here Insert Picture Description

with try-catch eval scope chain may vary

Published 158 original articles · won praise 44 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_43277404/article/details/104613354
Recommended