Table of Contents
Interviewer: Could you please briefly describe the differences between var, let, and const?
Interviewer: Please talk about your understanding of deep copy and shallow copy
Interviewer: What did the browser do the moment you entered the URL?
Interviewer: Tell me about the difference between cookie sessionStorage and localStorage?
Interviewer: What are the JS data types and what are the differences?
Interviewer: Tell me about your understanding of closures?
Interviewer: How many methods does JavaScript have to determine the type of a variable?
Interviewer: Let’s talk about null and undefined The difference, how to make a property null
Interviewer: Tell me about any methods to maintain real-time communication between the front and back ends?
Interviewer: Tell me the difference between pseudo array and array?
Home Web Front-end JS Tutorial Take a look at these front-end interview questions to help you master high-frequency knowledge points (6)

Take a look at these front-end interview questions to help you master high-frequency knowledge points (6)

Feb 24, 2023 pm 07:19 PM
javascript front end Interview questions

Take a look at these front-end interview questions to help you master high-frequency knowledge points (6)

10 questions every day, after 100 days, you will have mastered all the high-frequency knowledge points of front-end interviews, come on! ! ! , while reading the article, I hope you don’t look at the answers directly, but first think about whether you know it, and if so, what is your answer? Think about it and then compare it with the answer. Would it be better? Of course, if you have a better answer than mine, please leave a message in the comment area and discuss the beauty of technology together.

Interviewer: Could you please briefly describe the differences between var, let, and const?

Me: Uh~, okay, the differences between the three functions are summarized as follows:

var: The most commonly used variables; Repeated declarations are allowed, but data will be overwritten; variable promotion will occur; local variables are mounted on global objects, which will cause pollution of the global object.

console.log(a) // 因变量提升, var a;提到前面但是没有赋值,所以值为undefined
var a = 1
var a = '你好' // var声明的变量会被重新赋值
console.log(a) // a会打印被重新赋值的值
console.log(window.a) // var声明的局部变量会被挂载到全局变量上,造成全局变量的污染。
Copy after login

let: es6 new command, usage is similar to var; repeated declarations are not allowed; there is no variable promotion; often acts on block-level scope to avoid local Variables cause pollution of global variables.

let a=10;
console.log(a) // 不存在变量提升,所以值为:10
console.log(window.a) // 不会造成全局污染,所以值为 undefined
for(let i =0;i<3;i++){ // 会生成块级作用域,i 的值只能在块级作用域中使用
    console.log(i)
}
console.log(i) // 因为拿不到块级作用域中的值,所以报错。
Copy after login

const: es6 new command, used to declare constants and the values ​​cannot be modified; declared constants must be initialized immediately, otherwise an error will be reported when assigning values ​​later; repeated declarations are not allowed ;const points to the address of the variable. As long as the address referenced by the variable name remains unchanged, no error will be reported

const arr = [&#39;小张&#39;,&#39;小王&#39;,&#39;小李&#39;,&#39;小赵&#39;]
arr[0]=&#39;小明&#39;
console.log(arr) // [&#39;小明&#39;, &#39;小王&#39;, &#39;小李&#39;, &#39;小赵&#39;]
const arr = [] // 报错
Copy after login

Interviewer: Please talk about your understanding of deep copy and shallow copy

Me: Uh~, okay, the understanding of the two is summarized as follows:

Deep copy: New data and original data do not interfere with each other.

// 扩展运算符在一维数组中是属于深拷贝,在多维数组中属于浅拷贝
let arr = [1,2,3]
let newArr = [...arr]
newArr.push(4)
console.log(arr,newArr) // [1, 2, 3],[1, 2, 3, 4]

// 深拷贝用法
let list = [
    {id:1,name:&#39;张三&#39;,age:18},
    {id:2,name:&#39;李四&#39;,age:28},
    {id:3,name:&#39;王五&#39;,age:38},
]
let newList = JSON.parse(JSON.stringify(list))
newList.pop()
console.log(list.length,newList.length) // 3 2
Copy after login

Of course, there is also a standard way of writing deep copy, as follows:

// 标准的深拷贝 => 引用数据类型(数组,对象)
function deepClone(source){
    const targetObj = source.constructor === Array ? [] : {}
    for(let keys in source){
        if(source.hasOwnProperty(keys)){
            // 引用数据类型
            if(source[keys] && typeof source[keys] === 'object'){
                targetObj[keys] = source[keys].constructor === Array ? [] : {}
                // 递归
                targetObj[keys] = deepClone(source[keys])
            }else{
                // 基本数据类型,直接赋值
                targetObj[keys] = source[keys]
            }
        }
    }
    return targetObj
}

let obj = {
    name:'张三',
    age:18,
    hobby:['抽烟','喝酒','烫头'],
    action:{
        am:'敲代码',
        pm:'睡觉'
    }
}
let newObj = deepClone(obj)
newObj.name = '李四'
console.log(obj.name,newObj.name)// 张三 李四
Copy after login

Shallow copy: New data will affect the original data.

let arr = [1,2,3]
let newArr = arr
// 对新数据做出改变,原数据也会发生改变,这种就叫做浅拷贝
newArr.push(4) // [1, 2, 3, 4]
console.log(arr,newArr) // [1, 2, 3, 4]
Copy after login

To put it bluntly, deep copy is to obtain new data and has nothing to do with the original data; although shallow copy can obtain new data, it still has a certain connection with the original data.

Interviewer: What did the browser do the moment you entered the URL?

Me: Uh~, URL consists of the following parts:

https: Transport protocol (between http and tcp Added a layer of TSL or SSL security layer)

www: Server

baidu.com: Domain name

DNS domain name system will match the real IP, the first time access Normally, the second visit will store the IP resolved by the domain name locally and use it to read the browser cache.

The moment I entered the URL I experienced: Domain name -> DNS Domain Name System -> Get the real IP -> Establish a connection (TCP three-way handshake) -> Get the data, render the page -> Wave four times

Specific implementation process:

  • 1. URL parsing: determine whether to search for content or request URL

  • 2. Find the local cache: if there is a cache, return it directly to the page. If there is no cache, it will enter the network request stage

  • 3. DNS resolution

  • 4. Establish TCP connection through three-way handshake

  • 5. Synthesize request header information and send http request

  • 6. Process the response information

  • 7. Disconnect the TCP connection by waving four times

  • 8. If the response status code is 301, then Redirect

  • 9. The browser renders the page: 1) parses the HTML and generates a DOM tree; 2) calculates the node style according to the CSS and generates a stylesheet; 3) generates a layout tree; 4) Generate independent layers for specific elements

Me: Uh~, okay, the relationship between them is as follows:

Same points:

They are all browser storage, and they are all stored locally in the browser.

Difference:

  • 1.Cookie is written by the server or front end, sessionStorage and localStorage are both written by the front end Enter

  • 2. The life cycle of the cookie is set when the server writes it. LocalStorage will always exist as long as it is written, unless it is manually cleared. SessionStorage is automatically cleared when the page is closed.

  • 3. The cookie storage space is about 4kb, and the sessionStorage and localStorage spaces are relatively large, about 5M

  • 4.3 All data sharing follows the same origin principle, and sessionStorage is also restricted to the same page

  • 5. When the front end sends a request to the back end, Automatically carry cookies, session and local do not carry

  • 6. Cookies generally store login verification information or tokens. LocalStorage is often used to store data that is not easy to change and reduce server pressure. SessionStorage can be used Monitor whether the user refreshes to enter the page, such as the music player to restore the progress bar function

Interviewer: What are the JS data types and what are the differences?

Me: Uh~, JS data types are divided into two categories: one is basic data type, the other is reference data type, as follows:

  • Basic types: string, number, boolean, null, undefined, symbol, bigInt

  • Reference type: object, array

Basic types are stored in the stack, with small space and frequent operations

Reference types are stored in the heap, with large space, and are stored in the stack The pointer points to the starting address in the heap

Note: Symbol is unique and cannot be enumerated. Use getOwnPropertySymbols to obtain

Interviewer: Tell me about your understanding of closures?

Me: Uh~, the inner function refers to the variables in the outer function, and the set of these variables is the closure.

  • Principle of formation: Scope chain, the current scope can access variables in the superior scope.

  • Problem solved: It can prevent the variables in the function scope from being destroyed after the function execution ends, and it can also be used in the function Local variables inside the function can be accessed from the outside. Problems caused by

  • : Since the garbage collector will not destroy the variables in the closure, a memory leak occurs. If the leakage accumulates too much, it will easily lead to memory overflow.

  • Application of closure, can imitate block-level scope, can achieve currying, define privileged methods in the constructor, Closures, etc. are used in data responsive Observer in Vue.

Interviewer: How many methods does JavaScript have to determine the type of a variable?

Me: Uh~, okay, the summary is as follows:

1. typeof (based on binary judgment), cannot determine the data type: null and object

2 . intanceof (judged based on the prototype chain), the native data type cannot be judged

3. constructor.name (judged based on the constructor), the null data type cannot be judged

4. Object.prototype.toString .call() (use the toString method of Object to judge) all types of data can be judged. Remember that the judgment result is printed as: '[object Xxx]'

Interviewer: Let’s talk about null and undefined The difference, how to make a property null

Me: Uh~, null is defined and assigned null undefined is defined but not assigned.

Interviewer: Tell me about any methods to maintain real-time communication between the front and back ends?

Me: Uh~, polling, long polling, iframe streaming, WebSocket, SSE.

Interviewer: Tell me the difference between pseudo array and array?

Me: Uh~, okay, the summary is as follows:

Characteristics of pseudo arrays: The type is object, arrays cannot be used Methods, you can get the length, you can use for in to traverse

Pseudo arrays canConvert to arrays: Array.prototype.slice.call(), Array. from(), [...pseudo array]

There areWhich are pseudo arrays: function parameters arguments, Map and Set keys(), values( ) and entires()

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of Take a look at these front-end interview questions to help you master high-frequency knowledge points (6). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

PHP and Vue: a perfect pairing of front-end development tools PHP and Vue: a perfect pairing of front-end development tools Mar 16, 2024 pm 12:09 PM

PHP and Vue: a perfect pairing of front-end development tools. In today's era of rapid development of the Internet, front-end development has become increasingly important. As users have higher and higher requirements for the experience of websites and applications, front-end developers need to use more efficient and flexible tools to create responsive and interactive interfaces. As two important technologies in the field of front-end development, PHP and Vue.js can be regarded as perfect tools when paired together. This article will explore the combination of PHP and Vue, as well as detailed code examples to help readers better understand and apply these two

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Is Django front-end or back-end? check it out! Is Django front-end or back-end? check it out! Jan 19, 2024 am 08:37 AM

Django is a web application framework written in Python that emphasizes rapid development and clean methods. Although Django is a web framework, to answer the question whether Django is a front-end or a back-end, you need to have a deep understanding of the concepts of front-end and back-end. The front end refers to the interface that users directly interact with, and the back end refers to server-side programs. They interact with data through the HTTP protocol. When the front-end and back-end are separated, the front-end and back-end programs can be developed independently to implement business logic and interactive effects respectively, and data exchange.

Exploring Go language front-end technology: a new vision for front-end development Exploring Go language front-end technology: a new vision for front-end development Mar 28, 2024 pm 01:06 PM

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Django: A magical framework that can handle both front-end and back-end development! Django: A magical framework that can handle both front-end and back-end development! Jan 19, 2024 am 08:52 AM

Django: A magical framework that can handle both front-end and back-end development! Django is an efficient and scalable web application framework. It is able to support multiple web development models, including MVC and MTV, and can easily develop high-quality web applications. Django not only supports back-end development, but can also quickly build front-end interfaces and achieve flexible view display through template language. Django combines front-end development and back-end development into a seamless integration, so developers don’t have to specialize in learning

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

See all articles