本段 679 题 | 来源:fullstack + general + design | 知识点:前端
586. Can you explain the life cycle hook in vue.js?
你能解释一下 vue.js 中的生命周期钩子吗?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8d58d557c902bc95b2 | 官方: 否 | 付费: 否
答案:
The lifecycle hooks in Vue.js are special methods that are called at various stages of a component's lifecycle. These hooks allow the execution of code at specific points in the component's lifecycle, such as before the component is created before it is mounted, after it is updated, and before it is destroyed. - beforeCreate: This hook is called before the component instance is created. It is useful for initializing data and setting up event listeners.
Vue.js 中的生命周期钩子是在组件生命周期的各个阶段被调用的特殊方法。这些钩子允许在组件生命周期的特定点执行代码,例如在组件创建之前、挂载之前、更新之后以及销毁之前。- beforeCreate:此钩子在组件实例创建之前被调用。它对于初始化数据和设置事件监听器很有用。
- created: This hook is called after the component instance is created. It is useful for performing initial setups such as fetching data from an API.
- beforeMount: This hook is called before the component is mounted to the DOM. It is useful for performing any necessary DOM manipulations before the component is rendered.
- mounted: This hook is called after the component is mounted to the DOM. It is useful for performing any necessary DOM manipulations after the component is rendered.
- beforeUpdate: This hook is called before the component is updated due to changes in its props or state. It is useful for performing any necessary pre-update tasks.
- updated: This hook is called after the component is updated due to changes in its props or state. It is useful for performing any necessary post-update tasks.
- beforeUnmount: This hook is called before the component is unmounted from the DOM. It is useful for performing any necessary cleanup tasks before the component is removed from the DOM.
unmounted: This hook is called after the component is unmounted from the DOM. It is useful for performing any necessary cleanup tasks after the component is removed from the DOM.
By using these lifecycle hooks in your Vue.js components, you can execute code at specific points in the component's lifecycle, allowing you to perform initialization, cleanup, and other tasks as needed.通过在 Vue.js 组件中使用这些生命周期钩子,你可以在组件生命周期的特定时间点执行代码,从而按需执行初始化、清理和其他任务。
587. What are Hooks in Vue.js? Also, list various built-in Hooks.
Vue.js 中的 Hook 是什么?另外,请列出各种内置的 Hook。
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8d58d557c902bc95b5 | 官方: 否 | 付费: 否
答案:
Hooks are a new feature introduced in Vue.js 3. This allows adding logic and state management into components in a more organized and reusable way. Hooks are similar to lifecycle hooks, but they allow for encapsulation and reuse of logic across multiple components.
Hook 是 Vue.js 3 中引入的一个新特性。它允许以更有组织性和可复用的方式将逻辑和状态管理添加到组件中。Hook 类似于生命周期钩子,但它们允许在多个组件中封装和复用逻辑。
Vue.js provides several built-in hooks that we can use to add functionality to the components. Some of the most commonly used hooks include: - 'setup’: This is the main hook that you use to add logic and state management to the component. The setup function is called before the component is created, and it allows the definition of reactive data, methods, computed properties, and other logic that can be accessed by the component's template.
Vue.js 提供了几个内置的 Hook,我们可以使用它们来为组件添加功能。一些最常用的 Hook 包括:- “setup”:这是你用来向组件添加逻辑和状态管理的主要 Hook。setup 函数在组件创建之前被调用,它允许定义响应式数据、方法、计算属性以及组件模板可以访问的其他逻辑。
- ‘onMounted’: This hook is called after the component is mounted to the DOM. We can use this hook to perform any necessary DOM manipulations or data fetching operations.
- ‘onUpdated’: This hook is called after the component is updated due to changes in its props or state. We can use this hook to perform any necessary post-update tasks.
- ‘onUnmounted’: This hook is called before the component is unmounted from the DOM. We can use this hook to perform any necessary cleanup tasks before the component is removed from the DOM.
588. What is Data Binding in Vue.js? And how many types of Data Binding are there in Vue.js?
什么是 Vue.js 中的数据绑定?Vue.js 中有多少种数据绑定类型?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8d58d557c902bc95b8 | 官方: 否 | 付费: 否
答案:
Data binding is the process of synchronizing data between the Vue instance and the DOM. It allows us to establish a connection between the data and the UI, so that any changes to the data are automatically reflected in the UI, and any changes to the UI are automatically reflected in the data.
数据绑定是同步 Vue 实例与 DOM 之间数据的过程。它允许我们在数据和 UI 之间建立连接,因此对数据的任何更改都会自动反映在 UI 中,而对 UI 的任何更改也会自动反映在数据中。
There are three types of data binding in Vue.js:
Vue.js 中有三种数据绑定类型:
Interpolation: This is a one-way binding that allows us to embed the value of a data property into the content of an HTML element. It is denoted by double curly braces ‘{}’. For example, ‘{{ message }}’ would bind the value of the message data property to the content of the HTML element. 2. Property binding: This is a one-way binding that allows us to set the value of an HTML element's attribute to the value of a data property. It is denoted by the ‘v-bind’ directive. For example, (v-bind:href="url") would bind the value of the ‘url’ data property to the ‘href’ attribute of an HTML element. 3. Two-way binding: This allows us to bind the value of a form input element to a data property, so that changes to the input elements are reflected in the data, and vice versa. It is denoted by the ‘v-model’ directive. For example, (v-model="message") would bind the value of the ‘message’ data property to the value of a form input element.
- 插值:这是一种单向绑定,允许我们将数据属性的值嵌入到 HTML 元素的内容中。它由双花括号 ‘{}’ 表示。例如,‘{{ message }}’ 会将 message 数据属性的值绑定到 HTML 元素的内容。 2. 属性绑定:这是一种单向绑定,允许我们将 HTML 元素属性的值设置为数据属性的值。它由 ‘v-bind’ 指令表示。例如, (v-bind:href="url") 会将 ‘url’ 数据属性的值绑定到 HTML 元素的 ‘href’ 属性。 3. 双向绑定:这允许我们将表单输入元素的值绑定到数据属性,以便对输入元素的更改反映在数据中,反之亦然。它由 ‘v-model’ 指令表示。例如, (v-model="message") 会将 ‘message’ 数据属性的值绑定到表单输入元素的值。
589. How do you pass data between components in Vue.js?
如何在 Vue.js 中的组件之间传递数据?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8d58d557c902bc95bb | 官方: 否 | 付费: 否
答案:
We can pass data between components in the following ways- - Props: It is like an argument that is given to the component. The term used to define this is an attribute. This is registered on the component and it allows to pass of the data from the parent component to the child component. To pass data through props, we can define the prop on the child component, and then bind the data to the prop on the parent component.
我们可以通过以下方式在组件之间传递数据:- Props:这类似于传递给组件的参数。用来定义它的术语是属性。它在组件上注册,并允许将数据从父组件传递到子组件。要通过 props 传递数据,我们可以在子组件上定义 prop,然后在父组件上将数据绑定到该 prop。
For example:
例如:
- Event bus: An event bus is a Vue instance that you can use to emit and listen to events across different components. To pass data using an event bus, we can simply emit an event with the data from one component, and then listen for the event and receive the data in another component.
For example:
例如:
// Event bus instance
// 事件总线实例
export const bus = new Vue()
export const bus = new Vue()
// Emitting an event with data in Component A
// 在组件A中发射一个带有数据的事件
bus.$emit('my-event', data)
bus.$emit('my-event', data)
// Listening for the event and receiving data in Component B
// 在组件B中监听该事件并接收数据
bus.$on('my-event', data => {
bus.$on('my-event', data => {
// Do something with the data
// 对数据执行某些操作
})
- Vuex store: Vuex is a state management pattern and library for Vue.js applications. It allows us to define a centralized store for managing the state of your application and provides a way to access and mutate the state from different components. To pass data using a Vuex store, we can simply define a state property and mutation method in the store, and then dispatch the mutation with the data from one component, and then access the state property in another component.
For example:
例如:
// Store instance with state property and mutation
// 具有状态属性和变更的Store实例
export const store = new Vuex.Store({
export const store = new Vuex.Store({
state: {
state: {
message: ''
message: ''
},
mutations: {
mutations: {
setMessage (state, payload) {
setMessage (state, payload) {
state.message = payload
state.message = payload
}
}
})
// Dispatching the mutation with data in Component A
// 在组件A中分发变更(mutation)并携带数据
store.commit('setMessage', data)
store.commit('setMessage', data)
// Accessing the state property in Component B
// 在组件B中访问状态属性
this.message = this.$store.state.message
this.message = this.$store.state.message
590. What is the difference between one-way data flow and two-way data binding in Vue.js?
Vue.js中单向数据流和双向数据绑定有什么区别?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95be | 官方: 否 | 付费: 否
答案:
| One-way data flow | Two-way data binding |
|---|---|
| Definition | Data flows only from parent to child components. |
| Data flows between parent and child components in both directions. | |
| Syntax | Data is passed down from parent to child components through props. |
| Data is bound to form input elements using the ‘v-model’ directive. | |
| Example | |
| Benefits | 1. Simpler data flow, easier to track data changes. - Improved performance due to unidirectional data flow. |
| 1. Easier to handle user input and form data. |
Reduces the amount of code needed to handle data synchronization. |
Drawbacks
缺点1. More complex to implement a two-way data flow. - Can make it harder to track data changes.
1. 实现双向数据流更加复杂。 - 可能使跟踪数据变化变得更困难。1. Can make it harder to track data changes.
1. 可能使跟踪数据变化变得更困难。- More complex data flow can reduce performance. |
591. What is a filter in Vue.js? Provide an example.
Vue.js中的过滤器是什么?请提供一个示例。
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95c1 | 官方: 否 | 付费: 否
答案:
In Vue.js, filters are functions that can be used to transform data in a template expression. Filters allow us to apply a specific formatting or transformation to a piece of data before it is displayed in the user interface.
在Vue.js中,过滤器是可用于在模板表达式中转换数据的函数。过滤器允许我们在数据显示在用户界面之前,对数据应用特定的格式化或转换。
Filters are defined as functions that take a value as their input, perform some transformation on that value, and then return the transformed value.
过滤器被定义为函数,它们将值作为输入,对该值执行一些转换,然后返回转换后的值。
Filters can be added to a Vue.js application using the Vue.filter() method, and can then be used in template expressions using the ‘|’ character.
过滤器可以使用Vue.filter()方法添加到Vue.js应用程序中,并且可以在模板表达式中使用“|”字符来调用。
Example -
示例 -
Vue.filter('reverse', function(value) {
Vue.filter('reverse', function(value) {
// Reverse the characters in the string
// 反转字符串中的字符
return value.split('').reverse().join('')
return value.split('').reverse().join('')
})
new Vue({
new Vue({
el: '#app',
el: '#app',
data: {
data: {
message: 'Hello, world!',
message: '你好,世界!',
},
})
In this example, we have defined a reverse filter that takes a string as its input, then it reverses the characters in the string, and then returns the reversed string. We have then created a new Vue instance, and then set the message data property to 'Hello, world!'.
在这个示例中,我们定义了一个 reverse 过滤器,它接收一个字符串作为输入,然后反转字符串中的字符,最后返回反转后的字符串。接着我们创建了一个新的 Vue 实例,并将 message 数据属性设置为 '你好,世界!'。
To use the reverse filter in a template expression, we can simply pipe the message property through the filter using the ‘|’ character. Consider the below snippet to understand it.
要在模板表达式中使用 reverse 过滤器,我们可以简单地通过 '|' 字符将 message 属性传递给过滤器。考虑下面的代码片段来理解它。
{{ message | reverse }}
>{{ message | reverse }}
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
592. Explain the difference between ‘v-if’ and ‘v-show’ in Vue.js?
解释 Vue.js 中 'v-if' 和 'v-show' 的区别?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95c4 | 官方: 否 | 付费: 否
答案:
‘v-if’ and ‘v-show’ are both directives that allow conditional rendering of elements in the user interface. However, they differ in how they work and when they should be used. The differences are:
'v-if' 和 'v-show' 都是允许在用户界面中进行条件渲染元素的指令。然而,它们在工作方式和使用时机上有所不同。区别如下:
| Feature 特性 | v-if | v-show |
|---|---|---|
| Initial render 初始渲染 | Element is not included in the DOM. 元素不包含在 DOM 中。 | Element is included in the DOM but hidden. 元素包含在 DOM 中但被隐藏。 |
| Re-render 重新渲染 | Element is added or removed from the DOM. 元素从 DOM 中添加或移除。 | Element's display style property is toggled. 元素的 display 样式属性被切换。 |
| Performance 性能 | More efficient for elements that are rarely used. 对于很少使用的元素更高效。 | More efficient for elements that are frequently used. 对于经常使用的元素更高效。 |
| Conditional logic 条件逻辑 | It can be used with v-else and v-else-if. 可以与 v-else 和 v-else-if 一起使用。 | It cannot be used with v-else or v-else-if. 不能与 v-else 或 v-else-if 一起使用。 |
| Use case 使用场景 | It is best for elements that are rarely shown or hidden. 最适合很少显示或隐藏的元素。 | It is best for elements that are frequently shown or hidden. 最适合经常显示或隐藏的元素。 |
593. What is a template in Vue.js? How does it differ from regular HTML?
Vue.js 中的模板是什么?它与常规 HTML 有何不同?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95c7 | 官方: 否 | 付费: 否
答案:
A template is a piece of HTML that defines the structure and layout of a component in a Vue.js application. These are very similar to regular HTML code, but they also include Vue-specific syntax and directives. This allows binding data to the user interface, handling user input, and conditionally rendering content based on data and user interactions.
模板是定义 Vue.js 应用程序中组件结构和布局的一段 HTML。它们与常规 HTML 代码非常相似,但也包含 Vue 特有的语法和指令。这允许将数据绑定到用户界面、处理用户输入,并根据数据和用户交互条件渲染内容。
There are differences between a Vue.js template and regular HTML. The differences are - - Vue-specific syntax: Templates include special syntax and directives. This allows binding data to the user interface and performing other dynamic operations. For example - We can use double curly braces ({}) to output data values. Also, we can use v-bind to bind HTML attributes to data properties.
Vue.js 模板与常规 HTML 之间存在差异。差异如下 - - Vue 特有语法:模板包含特殊的语法和指令。这允许将数据绑定到用户界面并执行其他动态操作。例如 - 我们可以使用双花括号({})来输出数据值。此外,我们可以使用 v-bind 将 HTML 属性绑定到数据属性。
- Reactivity: Templates are reactive. It means that the template can automatically update in response for changing in data and user interactions. When the data changes in a Vue.js application, the corresponding templates are automatically re-renders to reflect the new state of the application.
- Directives: Vue.js templates include several built-in directives that allow us to perform complex operations. For Example - We can render data values conditionally using (v-if, v-else, v-show), we can easily loop over arrays and objects using (v-for), and handle user input using (v-on).
- Components: Templates in vue.js can also be used to define the components. Components can be reused and can compose UI elements that can be utilized in the entire application. Components are defined using a combination of a template, script, and style, and can be nested inside other components to create complex UI structures.
594. What are Routers?
什么是路由器?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95ca | 官方: 否 | 付费: 否
答案:
The Vue.js router is a library that allows the implementation of client-side routing in Vue.js applications. Here routing means the process of mapping URLs to specific components or views in the application. Routing allows users to navigate between different pages or views without refreshing a full page reload. So when the entire page doesn't refresh it feels like using a mobile / desktop application. Since the entire page didn’t get reloaded, it improves the performance also.
Vue.js 路由器是一个允许在 Vue.js 应用程序中实现客户端路由的库。这里路由是指将 URL 映射到应用程序中特定组件或视图的过程。路由允许用户在不同页面或视图之间导航,而无需刷新整个页面。因此,当整个页面不刷新时,感觉就像在使用移动/桌面应用程序。由于整个页面没有重新加载,它也提高了性能。
595. What is the difference between $emit and $on in Vue.js?
Vue.js 中 $emit 和 $on 的区别是什么?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95cd | 官方: 否 | 付费: 否
答案:
| $emit | $on |
|---|---|
| It is called on a child component to emit an event. 在子组件上调用以发出事件。 | It is called on a parent component to listen for an event. 在父组件上调用以监听事件。 |
| It can pass data as an optional second parameter. 可以将数据作为可选的第二个参数传递。 | It does not take any parameters. 不接受任何参数。 |
| It can emit events with custom names. 可以发出具有自定义名称的事件。 | It listens for events with a specific name. 监听具有特定名称的事件。 |
| It can be used to communicate from child to parent components. 可用于从子组件向父组件通信。 | It can be used to communicate from child to parent or between sibling components. 可用于从子组件向父组件通信或兄弟组件之间通信。 |
| This is typically used in the child component's methods section. 通常在子组件的方法部分中使用。 | This is typically used in the parent component's created or mounted hook. 通常在父组件的 created 或 mounted 钩子中使用。 |
| It is used to trigger an action in the parent component in response to a user interaction or data change in the child component. 用于触发父组件中的操作,以响应子组件中的用户交互或数据更改。 | It is used to respond to events emitted by child components and update the parent component's state or trigger other actions. 用于响应子组件发出的事件,并更新父组件的状态或触发其他操作。 |
| Example: this.$emit('button-clicked', 'Hello from the child component')<br>示例:this.$emit('button-clicked', '来自子组件的问候') | Example: this.$on('button-clicked', this.onButtonClicked)<br>示例:this.$on('button-clicked', this.onButtonClicked) |
596. What are the global and local components in Vue.js?
Vue.js中的全局组件和局部组件是什么?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95d0 | 官方: 否 | 付费: 否
答案:
Components are the fundamental building blocks of an application. This contains a piece of HTML, CSS, and JavaScript code and is encapsulated into a single function and shares this code across different parts of the application. By using components, we can avoid code duplication, And we can reuse the component as many times as it is required in the application. In vue.js, components are of two types - - Global components - Global components are defined at the top and can be used anywhere in the application. Mostly, we define global components in the main.js file or in a separate file and then import them into the application. We can register global components using the Vue.component() method.
组件是应用程序的基本构建块。它包含一段HTML、CSS和JavaScript代码,被封装成一个单独的函数,并在应用程序的不同部分共享这段代码。通过使用组件,我们可以避免代码重复,并且可以在应用程序中按需多次复用组件。在Vue.js中,组件分为两种类型——全局组件——全局组件在顶层定义,可以在应用程序的任何地方使用。通常,我们在main.js文件或单独的文件中定义全局组件,然后将它们导入应用程序。我们可以使用Vue.component()方法注册全局组件。
Example-
示例-
// Defining a global component
// 定义一个全局组件
Vue.component('global-component', {
Vue.component('global-component', {
template: `
template: `
Global Component
>全局组件
This is a global component.
>这是一个全局组件。
`
})
// Using the global component in a Vue instance
// 在Vue实例中使用全局组件
new Vue({
new Vue({
el: '#app',
el: '#app',
template: `
template: `
`
})
- Local components, on the other hand, are defined within a specific component and can only be used within that component or its child components. They are registered using the components option of the parent component.
Example-
示例-
// Define a local component
// 定义一个局部组件
const LocalComponent = {
const LocalComponent = {
template: `
template: `
Local Component
>本地组件
This is a local component.
>这是一个本地组件。
`
}
// Use the local component in a parent component
// 在父组件中使用本地组件
Vue.component('parent-component', {
Vue.component('parent-component', {
components: {
components: {
'local-component': LocalComponent
'local-component': LocalComponent
},
template: `
template: `
`
})
In this example, LocalComponent is a local component that is defined within the parent component. It can only be used within parent-component or child components.
在这个示例中,LocalComponent 是一个在父组件内部定义的本地组件。它只能在 parent-component 或子组件中使用。
597. What are custom key modifier aliases? How do you define it?
什么是自定义按键修饰符别名?如何定义它?
- 知识点: 前端 (主题: vue, javascript, frontend;标签: interviewbit, vue-js, topic-specific, vue, javascript, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c8e58d557c902bc95d3 | 官方: 否 | 付费: 否
答案:
Key modifiers are used to handle keyboard events. They allow you to listen to specific key events and perform actions in response. By default, Vue.js provides some key modifiers such as (.enter, .tab, .delete, etc) . However, you can define your own custom key modifier aliases using the Vue.config.keyCodes object.
按键修饰符用于处理键盘事件。它们允许你监听特定的按键事件并执行相应的操作。默认情况下,Vue.js 提供了一些按键修饰符,如(.enter、.tab、.delete 等)。然而,你可以使用 Vue.config.keyCodes 对象定义自己的自定义按键修饰符别名。
Example for defining a custom key modifier alias:
定义自定义按键修饰符别名的示例:
Vue.config.keyCodes.f2 = 113; // define a key modifier alias for the F2 key
Vue.config.keyCodes.f2 = 113; // 为 F2 键定义一个按键修饰符别名
In this example, we are defining a new key modifier alias for the F2 key with code 113.
在这个示例中,我们为代码为 113 的 F2 键定义了一个新的按键修饰符别名。
Once the custom key modifier alias has been defined, you can use it in your Vue.js templates like any other key modifier.
一旦定义了自定义按键修饰符别名,你就可以像使用其他按键修饰符一样,在 Vue.js 模板中使用它。
598. What processes are triggered when we type an URL into a browser and hit enter?
当我们在浏览器中输入 URL 并按下回车键时,会触发哪些过程?
- 知识点: 前端 (标签: interviewbit, walmart, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 沃尔玛
- id: 69b37c9058d557c902bc96bd | 官方: 否 | 付费: 否
答案:
Following are the actions taken by the browser whenever we type an URL into a browser and hit enter: - To find the website's corresponding IP address, the browser scans the cache for DNS entries. It searches for the following cache:
每当我们向浏览器中输入 URL 并按下回车键时,浏览器会执行以下操作:- 为了找到该网站对应的 IP 地址,浏览器会扫描缓存中的 DNS 条目。它会搜索以下缓存:
Browser Cache Operating Systems Cache Router Cache ISP CacheIf nothing is found in one, it moves on to the next until it is successful. If the domain name is not discovered in the cache, the DNS server of the ISP (Internet Service Provider) performs a DNS query to determine the IP address of the server that hosts the domain name. - Small data packets, containing the request's content and the IP address it's destined for, are sent.
浏览器缓存 操作系统缓存 路由器缓存 ISP缓存如果在一个缓存中找不到,就会继续查找下一个,直到成功。如果域名在缓存中未找到,ISP(互联网服务提供商)的DNS服务器会执行DNS查询,以确定托管该域名的服务器的IP地址。 - 发送包含请求内容及其目标IP地址的小数据包。
- The browser uses synchronize(SYN) and acknowledge(ACK) messages to establish a TCP (Transfer Control Protocol) connection with the server.
- The web server receives an HTTP request (either POST or GET) from the browser.
- The server on the host computer processes the request and responds. It generates a response in one of several formats, including JSON, XML, and HTML.
- The server sends out an HTTP response with the response status.
- HTML content is then displayed by the browser.
599. Explain doctype.
解释 doctype。
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9258d557c902bc988a | 官方: 否 | 付费: 否
答案:
Every HTML or XHTML document must begin with a declaration of the document type, which is called DOCTYPE; this is often the first line of code. It is not an element or tag, but rather a way for browsers to identify the standard/version of HTML or any other markup language that the current page is written in. A document type declaration is required for each HTML document to ensure that pages display as intended.
每个 HTML 或 XHTML 文档都必须以文档类型声明开头,这称为 DOCTYPE;这通常是代码的第一行。它不是元素或标签,而是浏览器识别当前页面所编写的 HTML 或其他标记语言的标准/版本的一种方式。每个 HTML 文档都需要文档类型声明,以确保页面按预期显示。
Syntax:
语法:
< !DOCTYPE html >
< !DOCTYPE html >
Example
示例
<!DOCTYPE html>
<!DOCTYPE html>
Scaler Academy
Scaler Academy
This is HTML5 Doctype Tag!
这是HTML5 Doctype标签!
600. When should you use HTML5 tags such as STRONG, EM, SMALL?
什么时候应该使用HTML5标签,如STRONG、EM、SMALL?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc988d | 官方: 否 | 付费: 否
答案:
While these tags provide a unique visual effect (STRONG makes the text bold, EM italicized it, and SMALL shrinks it), this is not their primary purpose, and they should not be used simply to style a piece of content in a specific way. Unlike some other tags, these ones provide a unique visual effect (STRONG makes the text bold, EM italicized it, and SMALL shrinks it). However, they are not intended to provide a visual effect, nor should they simply be used to style content in a particular way. - tag: Used to mark up the emphasized text.
虽然这些标签提供了独特的视觉效果(STRONG使文本加粗,EM使其斜体,SMALL使其缩小),但这并不是它们的主要目的,它们不应仅仅用于以特定方式样式化内容。与其他一些标签不同,这些标签提供了独特的视觉效果(STRONG使文本加粗,EM使其斜体,SMALL使其缩小)。然而,它们并非旨在提供视觉效果,也不应仅仅用于以特定方式样式化内容。- 标签:用于标记强调的文本。
- tag: Often used in titles, headings, and paragraphs to emphasize the word or phrase of greatest significance. Also, it can be used to emphasize the seriousness or importance of a word or phrase.
- tag: Typically used for disclaimers, side comments, clarifications, etc.
601. Can a web page have multiple H1 tags? Would it matter?
一个网页可以有多个H1标签吗?这有关系吗?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9890 | 官方: 否 | 付费: 否
答案:
H1 tags can be used as many times as you like on a web page, as there is no upper or lower limit. A website's H1 (title) tag is of great importance to search engines and other machines that read the code of a web page and interpret its contents. It is generally recommended that web pages contain only one H1 tag. Multiple H1 tags can, however, be used as long as they are not overused, and are contextually relevant to the structure of the page. H1 is considered the main heading or title of an article, document, or section. It may be detrimental to the website's SEO performance if H1 elements are not used properly.
H1标签可以在网页上随意使用多次,因为没有上限或下限。网站的H1(标题)标签对搜索引擎和其他读取网页代码并解释其内容的机器非常重要。通常建议网页只包含一个H1标签。然而,只要不过度使用,并且与页面结构上下文相关,可以使用多个H1标签。H1被认为是文章、文档或部分的主标题。如果H1元素使用不当,可能对网站的SEO性能产生不利影响。
602. What format would you use to embed self-hosted video on a web site?
你会使用什么格式在网站上嵌入自托管视频?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9893 | 官方: 否 | 付费: 否
答案:
When you embed a video on a website using HTML5 video (instead of using YouTube or another video-hosting service), the website must ensure that the video is served in a format that the browser can play. The MP4 video format is currently supported by major browsers, operating systems, and devices (using MPEG4 or h.264 compressions). For Firefox clients and some Android devices that are not capable of playing MP4 videos, having copies of the video in OGV and WebM formats is helpful.
当您使用HTML5视频在网站上嵌入视频(而不是使用YouTube或其他视频托管服务)时,网站必须确保视频以浏览器可以播放的格式提供。目前,主流浏览器、操作系统和设备(使用MPEG4或h.264压缩)支持MP4视频格式。对于无法播放MP4视频的Firefox客户端和一些Android设备,拥有OGV和WebM格式的视频副本会很有帮助。
603. How does white space affect the content on the webpage?
空白如何影响网页上的内容?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9896 | 官方: 否 | 付费: 否
答案:
White space, also referred to as empty space or negative space in web design, refers to the unused space that surrounds the content and functional elements of a web page. With white space, you make your design breathe by minimizing the amount of text and functionality users see at once. - By using white space, you can visually group and separate elements, draw attention to a specific element, and reinforce a content grid or layout in web design and other media.
空白,在网页设计中也被称为空空间或负空间,指的是围绕网页内容和功能元素的未使用空间。通过空白,你可以减少用户一次看到的文本和功能数量,使设计更透气。- 通过使用空白,你可以在网页设计和其他媒体中视觉上分组和分离元素,吸引注意力到特定元素,并强化内容网格或布局。
- Aside from contributing to the harmony and balance of a design and assisting the branding process, whitespace can also be utilized to direct the reader from one element to the next.
- This makes the website appear clean and uncluttered, providing readers with the information they will enjoy.
- Data Science
- All Events
- My Events
604. What is W3C and how does it affect web design?
什么是W3C,它如何影响网页设计?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9899 | 官方: 否 | 付费: 否
答案:
An international organization, the World Wide Web Consortium (W3C) promotes web development. Members of the organization, a full-time staff, experts invited from around the world, and the public collaborate together to create Web Standards. Also, W3C develops standards for the World Wide Web (WWW) to facilitate interoperability and collaboration between all web stakeholders. Since its inception in 1994, W3C has endeavored to lead the web towards a fuller potential.
万维网联盟(W3C)是一个国际组织,促进web开发。该组织的成员、全职员工、来自世界各地的特邀专家和公众共同协作创建Web标准。此外,W3C为万维网(WWW)开发标准,以促进所有web利益相关者之间的互操作性和协作。自1994年成立以来,W3C一直致力于引领web走向更充分的潜力。
605. Explain information architecture.
解释信息架构。
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: system-design
- 分类: fullstack
- id: 69b37c9358d557c902bc989c | 官方: 否 | 付费: 否
答案:
Information architecture (IA) refers to the process of planning, organizing, structuring, and labeling content in a comprehensive, logical, and sustainable manner. It serves as a means of structuring and classifying content in a way that is clear and understandable, so users can find what they are looking for with little effort. IA may also be used to redesign an existing product, rather than being limited to new products. Essentially, it determines how users will access your website information as well as how well their user experience will be.
信息架构(IA)指的是以全面、逻辑和可持续的方式规划、组织、构建和标记内容的过程。它是一种以清晰易懂的方式构建和分类内容的手段,使用户能够轻松找到所需信息。IA也可用于重新设计现有产品,而不仅限于新产品。本质上,它决定了用户如何访问你的网站信息,以及他们的用户体验质量如何。
606. What are the most common problems in website design?
网站设计中最常见的问题有哪些?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc989f | 官方: 否 | 付费: 否
答案:
A few of the most common website design problems include: - An outdated or inadequate web design.
一些最常见的网站设计问题包括: - 过时或不充分的网页设计。
- Poor website navigation.
- Ineffective SEO strategies.
- Convoluted or unclear user journeys.
- Excessive use of images, icons, colors, and textures.
- Lack of quality content.
- Poor quality images.
- Hidden contact details.
- Upload time is extremely slow.
- Mobile optimization is not available.
607. What should you consider when writing an error message?
编写错误消息时应考虑哪些因素?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98a2 | 官方: 否 | 付费: 否
答案:
Although the error message may seem innocuous, it has a big impact on the user's experience. Error messages written poorly can frustrate users, while well-written error messages increase users' subjective satisfaction and speed. One should consider the following factors when writing an error message: - Write in clear, simple language, without ambiguity, so that the issue can be understood easily.
尽管错误消息可能看似无害,但它对用户体验有很大影响。写得不好的错误消息会让用户感到沮丧,而写得好的错误消息能提高用户的主观满意度和速度。编写错误消息时应考虑以下因素: - 使用清晰、简单的语言,避免歧义,以便问题容易被理解。
- Keep it concise, precise, and meaningful.
- Be humble and don't blame users as tone and language are major factors in how they interpret your message.
- Refrain from using words that are negative.
- Provide a solution to resolve the error.
- Format your error messages correctly.
- Don't overwhelm users with error messages.
608. What do you mean by grid system?
你所说的网格系统是什么意思?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98a5 | 官方: 否 | 付费: 否
答案:
In graphic design, grid systems provide a two-dimensional framework for aligning and laying out elements. This is a set of measurements that the designer can use to size and align objects within a certain format. It is composed of horizontal and vertical lines that intersect, allowing the contents to be arranged on the page. A grid can facilitate the positioning of multiple design elements on a website in a way that is visually appealing, facilitates a user's flow, and improves accessibility and the attractiveness of information and visuals. A grid can also be broken down into several subtypes, each with its own specific application in web design.
在平面设计中,网格系统提供了一个二维框架,用于对齐和布局元素。这是一组测量值,设计师可以在特定格式中使用它来调整对象的大小和位置。它由相交的水平和垂直线组成,允许内容在页面上排列。网格可以以视觉吸引人的方式促进网站上多个设计元素的定位,便于用户流程,并提高信息和视觉的可访问性和吸引力。网格还可以细分为多种子类型,每种在网页设计中都有其特定应用。
609. Which color would you choose as a web designer when declaring the "delete" button?
作为网页设计师,在声明“删除”按钮时你会选择哪种颜色?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98a8 | 官方: 否 | 付费: 否
答案:
By using a color like Red, you can make the "Delete" button more visible, especially if two buttons have to be displayed simultaneously. Almost always, red is used as a symbol of caution, so that is a great way to get the user's attention.
使用红色这样的颜色可以使“删除”按钮更显眼,尤其是当两个按钮需要同时显示时。几乎总是,红色被用作警示的象征,因此这是吸引用户注意力的好方法。
610. How do you set an image as the background of a web page?
如何将图像设置为网页的背景?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98ab | 官方: 否 | 付费: 否
答案:
Background images provide a visually appealing and interactive background to a website. These images can be applied in many ways.
背景图像为网站提供视觉上吸引人且交互式的背景。这些图像可以通过多种方式应用。
- In the body tag, pass the URL or location path of a background image in the background attribute.
Syntax
语法
Website Body
网站主体
Example
示例
<!DOCTYPE html>
<!DOCTYPE html>Scaler Academy Scaler Academy
Welcome to Scaler Family
欢迎来到Scaler大家庭
- Add CSS style properties.
Syntax
语法
Example
示例
<!DOCTYPE html>
<!DOCTYPE html>
Scaler Academy
Scaler Academy
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
611. Explain responsive web design.
解释响应式网页设计。
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98ae | 官方: 否 | 付费: 否
答案:
The responsive web design process involves creating a web page that "responds" to or resizes itself to fit whatever screen size the viewer is using. This involves the use of HTML and CSS to resize, shrink, hide, and enlarge a website so that it appears correctly on all device resolutions (desktops, laptops, tablets, and phones). With responsive design, you can have one website that adapts to different screens and devices according to their sizes.
响应式网页设计过程涉及创建一种能够“响应”或根据观看者使用的屏幕尺寸自动调整大小的网页。这利用HTML和CSS来调整、缩小、隐藏和放大网站,以确保其在所有设备分辨率(台式机、笔记本电脑、平板电脑和手机)上正确显示。通过响应式设计,您可以拥有一个能根据不同屏幕和设备的尺寸进行自适应调整的网站。
612. What are the most widely used languages for web design?
网页设计中最广泛使用的语言有哪些?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98b1 | 官方: 否 | 付费: 否
答案:
The following are some common languages used in web design. Among the following, the most fundamental language for web design is HTML, which will provide you with a solid foundation for designing websites and web applications. In fact, it is probably the first language taught to a web designer, thereby making it an essential tool for all designers to have. - HTML (Hypertext Markup Language)
以下是一些常用于网页设计的语言。其中,网页设计最基本的语言是HTML,它将为您设计网站和Web应用提供坚实基础。实际上,它可能是网页设计师学习的第一门语言,因此成为所有设计师必备的工具。- HTML(超文本标记语言)
- CSS (Cascading Style Sheets)
- Java
- JavaScript
- SQL (Structured Query Language)
- PHP (Hypertext Processor)
- Python
613. Who is a web designer?
什么是网页设计师?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98b4 | 官方: 否 | 付费: 否
答案:
Simply put, a web designer is responsible for the appearance of a website. A web designer will take your ideas and create a mockup so that you can visualize the final look and feel of your website. Designers tend to possess expertise in UI (user interface), which means they create a site that is intuitive and easy to use. Designing a website is largely a creative process that involves organizing content and images across several web pages, integrating applications, and including other interactive elements. Some of their responsibilities include: - Design and layout websites according to client specifications.
简单来说,网页设计师负责网站的外观。网页设计师会将您的想法转化为模型,以便您直观地看到网站最终的外观和感觉。设计师通常精通UI(用户界面),这意味着他们创建的网站直观且易于使用。设计网站在很大程度上是一个创造性过程,涉及跨多个网页组织内容和图像、集成应用程序以及包含其他交互元素。他们的部分职责包括:- 根据客户规格设计和布局网站。
- Prepare mockups and samples for clients to review.
- Selecting readable fonts.
- Picking colors that are both attractive and easy-to-read.
- Using colors, fonts, and layouts to implement a brand's identity.
- Create a map of the website's structure to ensure a seamless navigation experience.
- Integrating images, texts, logos, videos, and other elements.
- Designing optimized versions of websites and pages for desktops and mobile devices.
614. What is web designing?
什么是网页设计?
- 知识点: 前端 / UI/UX 设计 (主题: web-design, frontend;标签: interviewbit, web-designer, topic-specific, web-design, frontend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98b7 | 官方: 否 | 付费: 否
答案:
In simple terms, web design refers to the process of creating the visual layout and look of a website so that they resonate with a company's brand, convey information, and support user-friendliness. Designing a website comprises many components that work together to create the overall user experience including graphic design, UX/UI design, SEO (Search Engine Optimization), and content creation. Whether you're building a website, mobile application, or maintaining content on a website, appearance and design are crucial elements. Since the mid-2010s, web design has increasingly been geared towards designing for mobile devices and tablet browsers.
简单来说,网页设计指创建网站的视觉布局和外观的过程,使其与公司品牌产生共鸣、传达信息并支持用户友好性。设计网站包含许多协同工作以创造整体用户体验的组件,包括图形设计、UX/UI设计、SEO(搜索引擎优化)和内容创建。无论您是构建网站、移动应用还是维护网站内容,外观和设计都是关键元素。自2010年代中期以来,网页设计越来越倾向于面向移动设备和平板浏览器进行设计。
615. State difference between SVG (Scalable Vector Graphics) and Canvas.
说明SVG(可缩放矢量图形)和Canvas之间的区别。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98f8 | 官方: 否 | 付费: 否
答案:
HTML5 introduced two new graphical elements, Canvas () and SVG (), that make your web pages more interactive and more graphically attractive. Each has its own properties and can be used to create graphic elements on web pages.
HTML5引入了两个新的图形元素,Canvas()和SVG(),使您的网页更具交互性和图形吸引力。每个都有自己的属性,可用于在网页上创建图形元素。
| tag 标签 | tag 标签 |
|---|---|
| In web pages, SVG is used to define vector-based graphics (vector image format). Unlike raster images (ex. .jpg, .gif, .png, etc. ), vector images can be stretched or compressed without losing quality. 在网页中,SVG用于定义基于矢量的图形(矢量图像格式)。与光栅图像(例如.jpg、.gif、.png等)不同,矢量图像可以在不损失质量的情况下进行拉伸或压缩。 | Canvas is a raster-based format composed of pixels. Canvas是一种基于光栅的格式,由像素组成。 |
| SVG provides better scalability, enabling high-quality printing at any resolution. SVG提供更好的可扩展性,支持以任何分辨率进行高质量打印。 | The canvas is not suitable for printing at high resolutions since it has poor scalability. Canvas不适合高分辨率打印,因为其可扩展性较差。 |
| Through scripting and CSS, SVG can be modified. 通过脚本和CSS,可以修改SVG。 | Modifying a canvas is only possible through the script. 修改Canvas只能通过脚本进行。 |
| The performance of SVG is better when dealing with fewer objects (10k). 在处理较少对象(10k)时,SVG的性能更好。 |
616. List the advantages of HTTP/2 over HTTP 1.1.
列举HTTP/2相对于HTTP 1.1的优势。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98fb | 官方: 否 | 付费: 否
答案:
Hypertext Transfer Protocol (HTTP) is a set of standard protocols allowing internet users to exchange website knowledge on WWW (World Wide Web). HTTP has gone through four iterations since it was introduced in 1991 i.e., HTTP/0.9, HTTP/1.0, HTTP/1.1, and HTTP/2.0. In 2015, HTTP/2 was released as a major revision to HTTP/1.1. HTTP/2.0 has the following advantages over HTTP/1.1:
超文本传输协议(HTTP)是一套标准协议,允许互联网用户在万维网(WWW)上交换网站知识。自1991年引入以来,HTTP经历了四次迭代,即HTTP/0.9、HTTP/1.0、HTTP/1.1和HTTP/2.0。2015年,HTTP/2作为HTTP/1.1的主要修订版发布。HTTP/2.0相比HTTP/1.1具有以下优势:
- Increased performance: It was designed specifically to speed up page loading and reduce round-trip time (RTT) for resource-intensive websites.
- Handle multiple resources: With HTTP 1.1, the web pages were manageable simply by using HTML markups and images. But with HTTP 2.0, there are now multiple resources available for web pages, including images, fonts, scripts, and more. HTTP 1.1 was not designed to handle such a large amount of resources today.
- Multiplexing: Multiplexing is fully implemented in HTTP/2. It means that multiple requests are sent between browsers and servers simultaneously over a single TCP connection. Consequently, several elements of a web page can be delivered via a single TCP connection. As a result, the HTTP/1.1 head-of-line blocking problem is resolved, in which a packet at the front of the line blocks the transmission of other packets.
- Header Compression: HTTP 2.0 has the ability to compress HTTP headers to reduce overhead. When HTML headers on web pages are compressed, they can be sent between the browser and server in one trip, over a single TCP connection.
- Server push: HTTP/2 servers are able to push resources into a browser's cache even before they are requested. By doing this, browsers can display content without requiring additional requests.
- Binary protocols: HTTP/2 use binary protocols, not textual. HTML/2's binary protocols consume less bandwidth, can be parsed more efficiently, and are less error-prone compared to HTTP/1.1's textual protocols.
617. Explain CORS (Cross-Origin Resource Sharing) and Write its Importance.
解释CORS(跨源资源共享)并写出其重要性。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc98fe | 官方: 否 | 付费: 否
答案:
CORS stands for Cross-origin resource sharing. It is basically defined as a browser mechanism that enables web pages from one domain to have controlled access to resources that are located at different domains (cross-domain request). In other words, it allows scripts running on a browser client to interact with and access resources from other origins. It provides and extends flexibility to the SOP (Same-Origin Policy). A same-origin policy restricts a website's ability to access resources outside its source domain. For example, if a JavaScript app wanted to call an API (Application Programming Interface) running on another domain, it would be blocked and prevented from doing so because of the SOP. Due to restrictions caused by the same-origin policy, CORS was introduced.
CORS代表跨源资源共享。它基本上定义为一个浏览器机制,允许来自一个域的网页对位于不同域的资源进行受控访问(跨域请求)。换句话说,它允许在浏览器客户端上运行的脚本交互并访问来自其他源头的资源。它为SOP(同源策略)提供并扩展了灵活性。同源策略限制网站访问其源域外部资源的能力。例如,如果JavaScript应用想要调用运行在另一个域上的API(应用程序编程接口),由于SOP,它会被阻止并禁止这样做。由于同源策略造成的限制,引入了CORS。
When a website's CORS policy is set up poorly, it also poses the risk of cross-domain attacks. As such, it cannot prevent cross-origin attacks such as CSRF (Cross-Site Request Forgery).
当网站的CORS策略设置不当,也会带来跨域攻击的风险。因此,它无法防止诸如CSRF(跨站请求伪造)之类的跨源攻击。
618. What do you mean by ETag (Entity Tag) and how does it work?
你所说的 ETag(实体标签)是什么意思?它是如何工作的?
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9901 | 官方: 否 | 付费: 否
答案:
The ETag (entity tag) is a part of the HTTP protocol. This is one of several mechanisms that HTTP provides to validate Web caches, which allows conditional requests to be made from a browser to resources. Moreover, Etags make sure that simultaneous updates of the same resource don't overwrite each other (mid-air collisions).
ETag(实体标签)是 HTTP 协议的一部分。这是 HTTP 提供的用于验证 Web 缓存的几种机制之一,它允许浏览器向资源发出条件请求。此外,ETag 确保对同一资源的并发更新不会相互覆盖(空中碰撞)。
ETags are opaque identifiers assigned by a server to a specific version of a resource found at a specific URL. Every time the resource representation at that URL changes, an entirely new ETag is assigned. As such, ETags can be compared in the same way as fingerprints and determine if two representations of a resource are identical.
ETag 是由服务器分配给位于特定 URL 的特定版本资源的不透明标识符。每当该 URL 处的资源表示发生变化时,就会分配一个全新的 ETag。因此,ETag 可以像指纹一样进行比较,以确定两个资源表示是否相同。
Syntax:
语法:
ETag: W/""
ETag: W/""
ETag: ""
ETag: ""
619. Explain Webpack.
解释一下 Webpack。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9904 | 官方: 否 | 付费: 否
答案:
Webpack is a tool that bundles JavaScript modules, also known as static module bundlers. Modules are reusable chunks of code that are built from the JavaScript, node_modules, images, and CSS styles of your application, and packaged so that they can be easily added to your website. If you have a large number of files, Webpack generates a single (or a few) file that runs your application.
Webpack 是一种打包 JavaScript 模块的工具,也被称为静态模块打包器。模块是可重复使用的代码块,由应用程序中的 JavaScript、node_modules、图片和 CSS 样式构建而成,并进行打包以便轻松添加到网站中。如果你有大量文件,Webpack 会生成一个(或几个)运行应用程序的文件。
When Webpack processes your application or package, it generates a dependency graph, which consists of various modules that your webapp needs in order to function as expected. Based on this graph, it then creates a new package that contains only the bare minimum files required, often only one or a few bundle.js files which can be easily plugged into the HTML file and used in the application.
当 Webpack 处理你的应用程序或包时,它会生成一个依赖图,其中包含你的 web 应用正常运行所需的各种模块。基于该依赖图,它会创建一个只包含所需最少文件的新包,通常只有一个或几个 bundle.js 文件,这些文件可以轻松插入到 HTML 文件中并在应用程序中使用。
- Data Science
- All Events
- My Events
620. List out newly introduced input types, APIs, form elements, and elements that support media content in HTML5.
列出 HTML5 中新增的输入类型、API、表单元素以及支持媒体内容的元素。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9907 | 官方: 否 | 付费: 否
答案:
List out newly introduced input types, APIs, form elements, and elements that support media content in HTML5.
列出 HTML5 中新增的输入类型、API、表单元素以及支持媒体内容的元素。
HTML5 has been updated repeatedly in the last few years, and the addition of input types has greatly simplified its use. Among some of these input types are - Colour: Enable users to select or choose a colour using the colour picker.
在过去的几年中,HTML5 已经多次更新,输入类型的增加极大地简化了其使用。其中一些输入类型包括:- 颜色:使用颜色选择器让用户选择或挑选颜色。
- Date: Enable users to select or choose a date from a drop-down calendar.
- Datetime-local: Enable users to select or choose both local date and time.
- Email: Enable users to enter an email address.
- Month: Enable users to select or choose a month and year from a drop-down calendar.
Week: Enable users to select or choose week and year from a drop-down calendar.
HTML5 introduces the following new form elements: - : Specifies a list of options for input controls.HTML5 引入了以下新的表单元素:- :为输入控件指定选项列表。
- : Creates an encryption key.
- : Defines the result or output of an expression.
- : Heads in the direction of 100% of the maximum value.
: Provides a gauge that shows a general value within a range.
The following are some of the new APIs introduced in HTML5: - History API: Provides programs with access to the browser's history.以下是 HTML5 中引入的一些新 API:- 历史 API:为程序提供访问浏览器历史的权限。
- Page visibility API: Enables us to determine the current visibility state of a page.
- Battery Status API: Displays the current battery status of the device.
- User Timing API: Provides programmers with high-precision timestamps for measuring application performance.
Vibration API: Provides access to the device's vibration functionality.
HTML5 includes five elements that support media as follows: - : Used to embed audio files in a web pageHTML5 包含五个支持媒体的元素,如下:- :用于在网页中嵌入音频文件
- : Used to embed video files in a web page.
- : Used for attaching multimedia files, including audio, video, and photos.
- : Used to embed external applications, usually multimedia content such as audio or video into an HTML document.
- : Specifies text tracks for audio and video components.
621. State the difference between span tag and div tag in HTML5.
说明 HTML5 中 span 标签和 div 标签的区别。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc990e | 官方: 否 | 付费: 否
答案:
Both the div and span tags are used to indicate the part of a web page. Divs are block-level elements, whereas spans are inline elements of a web page. tag is used to show block parts of the webpage whereas tag is used to show inline parts of the webpage:
这两种标签都用于指示网页的一部分。Div 是块级元素,而 span 是网页的内联元素。 标签用于显示网页的块部分,而 标签用于显示网页的内联部分:
Example:
示例:
一个为期6个月的在线职业加速器项目Scaler Academy| tag
标签 | tag
标签 |
| Span tag will be used for inline elements and for paragraphs. Span 标签用于行内元素和段落。 | Div tags are used for block-level elements. Div 标签用于块级元素。 |
| Typically, this tag is used to highlight any specific word ( or a small section of a line) on a webpage. 通常,此标签用于突出网页上的特定单词(或一行中的小部分)。 | In general, it is used/attached to highlight a section on the webpage. 通常,它用于附加以突出网页上的某个部分。 |
| In this tag, we use a specific colour code in order to highlight the HTML content. 在此标签中,我们使用特定颜色代码来突出显示 HTML 内容。 | In this tag, we use borders with height and width with specified colour pixels in order to highlight the HTML content. 在此标签中,我们使用带有指定颜色像素的边框(包括高度和宽度)来突出显示 HTML 内容。 |
| As it does not support the align attribute, the span tag will not appear on a new line. 由于不支持 align 属性,span 标签不会出现在新行上。 | With support for the align attribute, the div tag will appear on a new line. 由于支持 align 属性,div 标签会出现在新行上。 |
622. Explain HTML5 Web storage.
解释 HTML5 Web 存储。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9911 | 官方: 否 | 付费: 否
答案:
HTML5 has many great features, including Web Storage, which is sometimes referred to as DOM storage (Document Object Model Storage). Web applications can use Web Storage to store data locally in the browser on the user/client’s side. Data is stored in the form of a key/value pair in the user's browser. Using web storage to store data is similar to using cookies, but web storage is faster and more convenient. Web Storage should never be used to store sensitive data. It isn't "more secure" than cookies since it isn't transmitted over the wire and isn't encrypted.
HTML5 有许多优秀特性,包括 Web 存储,有时也称为 DOM 存储(文档对象模型存储)。Web 应用程序可以使用 Web 存储在用户/客户端侧的浏览器中本地存储数据。数据以键/值对的形式存储在用户的浏览器中。使用 Web 存储来存储数据类似于使用 Cookie,但 Web 存储更快且更方便。Web 存储绝不应用于存储敏感数据。它并不比 Cookie“更安全”,因为它不通过线路传输且未加密。
Types of Web Storage:
Web 存储的类型:
As outlined below, there are two types of web storage with different scopes and lifespans:
如下所述,有两种类型的 Web 存储,具有不同的作用域和生命周期:
- Local Storage: This storage uses Windows.localStorage object that stores data with no expiration date. Once stored in local storage, the data will remain available even after the user's browser is closed and reopened.
- Session Storage: This storage uses the Windows.sessionStorage object that stores data for one or single session only. As soon as the user closes his browser, data is lost or deleted from the browser, and the session would be lost.
623. Explain DOM (Document Object Model)?
解释 DOM(文档对象模型)?
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9914 | 官方: 否 | 付费: 否
答案:
DOM stands for Document Object Model. It is basically a cross-platform, language-independent API (Application Programming Interface) for XML (Extensible Markup Language) and HTML documents. To put it simply, DOM describes the logical structure of documents and how one can access and manipulate them. For example, here is an HTML document that illustrates the DOM hierarchy.
DOM 代表文档对象模型。它基本上是一种跨平台、与语言无关的 API(应用程序编程接口),用于 XML(可扩展标记语言)和 HTML 文档。简而言之,DOM 描述了文档的逻辑结构以及如何访问和操作它们。例如,这里是一个 HTML 文档,展示了 DOM 层级结构。
These documents are usually treated as a tree structure in which every node is an object that represents a specific part of the document. In a tree, each branch ends with a node, and each node contains objects. The DOM represents the webpage in a hierarchical structure in order for programmers and users to navigate it more easily.
这些文档通常被视为树结构,其中每个节点是一个对象,代表文档的特定部分。在树中,每个分支以节点结束,每个节点包含对象。DOM 以层级结构表示网页,以便程序员和用户更轻松地导航。
624. What do you know about pair programming?
关于结对编程,你知道什么?
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c9358d557c902bc9917 | 官方: 否 | 付费: 否
答案:
Pair programming is sometimes referred to as pairing. In pair programming, two programmers work together at one (single) workstation. Those who write code are known as drivers, and those who monitor and navigate each line of code are known as navigators. Both of them may switch roles frequently.
结对编程有时称为配对。在结对编程中,两个程序员在一个(单一)工作站上一起工作。编写代码的人称为驾驶员,而监控和导航每一行代码的人称为导航员。他们可能会频繁切换角色。
625. While building a web application, how do you consider SEO, maintainability, UX, performance, and security?
在构建 Web 应用程序时,你如何考虑 SEO、可维护性、UX、性能和安全性?
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc991a | 官方: 否 | 付费: 否
答案:
Security should be a top priority in any organization that handles vital data. On the other hand, SEO and UX should be prioritized for small and medium-sized online businesses. You will need to pay more attention to performance and SEO if you write an online publication.
在处理重要数据的任何组织中,安全性应是最优先事项。另一方面,对于中小型在线企业,应优先考虑 SEO 和 UX。如果你编写在线出版物,则需要更多关注性能和 SEO。
626. What are the key responsibilities of Web Developers?
Web 开发人员的主要职责是什么?
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc991d | 官方: 否 | 付费: 否
答案:
It is generally expected that web developers will be able to perform the following tasks: - Build products using HTML, CSS, JavaScript, PHP (Hypertext Preprocessor), and other relevant coding languages.
通常预期 Web 开发人员能够执行以下任务:- 使用 HTML、CSS、JavaScript、PHP(超文本预处理器)和其他相关编码语言构建产品。
- Design, develop, test, debug, and deploy applications in a cross-platform, cross-browser environment.
- Coordination with designers and programmers for the development of projects.
- Develop design specifications/patterns for optimizing web programs.
- Identifying and fixing bugs, troubleshooting, and resolving website issues.
- Taking care of the technical aspects of the site, such as its cache and performance (which indicate how fast a site will run and how much traffic it can handle).
- Providing support and assistance with web management best practices.
- Keep up with the latest technology.
- Maintain and update websites to meet modern web standards.
- Monitor web traffic.
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
627. What is the difference between <window.onload> and ?
<window.onload> 和之间有什么区别?
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9924 | 官方: 否 | 付费: 否
答案:
It is true that both the and functions perform tasks when the page has been loaded in the browser, however, the execution of the two functions differs slightly. - Window.onload: This event is triggered when a web page has fully loaded. In other words, it waits for the DOM and all the associated resources to load, and then executes code. DOM contains all HTML tags, like anchor tag, h1 tag, p tag, etc.
确实,“window.onload”和另一个函数(此处原文缺失)都在页面加载到浏览器后执行任务,但这两个函数的执行方式略有不同。- Window.onload:此事件在网页完全加载时触发。换句话说,它等待DOM和所有相关资源加载完成后执行代码。DOM包含所有HTML标签,如锚标签、h1标签、p标签等。
- onDocumentReady: The "onDocumentReady" method, on the other hand, executes the code when the DOM has been loaded. It typically waits for HTML tags, anchor tags, etc., but not for images, videos, or other contents.
628. Describe the different kinds of HTTP requests supported by RESTful Web services.
描述RESTful Web服务支持的不同类型的HTTP请求。
- 知识点: 前端 / 后端 (主题: web-development, frontend, backend;标签: interviewbit, web-developer, topic-specific, web-development, frontend, backend)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c9358d557c902bc9927 | 官方: 否 | 付费: 否
答案:
Each HTTP request type in RESTful web services has a specific purpose. Below is a description of them: - GET: It is used to retrieve data or resources from the server but only allows read-only access. You cannot modify it.
RESTful Web服务中的每种HTTP请求类型都有特定用途。以下是它们的描述:- GET:用于从服务器检索数据或资源,但仅允许只读访问。您不能修改它。
- POST: It is used for creating a new resource.
- PUT: This is similar to POST, but used for updating an existing resource (if the resource doesn't exist, the API will decide whether a new resource should be created).
- DELETE: It is used to delete the resource from the server.
- TRACE: It validates the content along with the network during an HTTP request.
629. What is the use of a CSS preprocessor? When should a pre-processor be utilised in a project, according to you?
CSS预处理器的用途是什么?您认为在项目中应何时使用预处理器?
- 知识点: 前端 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9758d557c902bc9b55 | 官方: 否 | 付费: 否
答案:
CSS preprocessors are scripting languages that augment CSS's standard functionality. They allow us to employ variables, nesting, inheritance, mixins, functions, and mathematical operations in our CSS code. CSS preprocessors make it simple to automate repetitive activities, eliminate code bloat and errors, develop reusable code snippets, and maintain backward compatibility.
CSS预处理器是脚本语言,可增强CSS的标准功能。它们允许我们在CSS代码中使用变量、嵌套、继承、混合、函数和数学运算。CSS预处理器使自动化重复性任务、消除代码臃肿和错误、开发可复用的代码片段以及保持向后兼容性变得简单。
The benefits and drawbacks of using a preprocessor vary depending on the type of project, but the following are some of the benefits and drawbacks.
使用预处理器的利弊因项目类型而异,但以下是一些优点和缺点。
Advantages: - You may add variables and functions to CSS with CSS Preprocessor, which gives it a new dimension and scope, making development easier and more efficient. It also improves the organization and cleanliness of your code.
优点: - 您可以使用CSS预处理器向CSS添加变量和函数,这为其赋予了新的维度和范围,使开发更容易、更高效。它还改善了代码的组织性和整洁性。
- CSS Preprocessors is a unique feature that allows you to combine numerous stylesheets into one. You can make separate files for each screen or page, then combine them in the main CSS file.
- The CSS Preprocessor assists you in avoiding repetitions. Instead of rewriting common styles, you can write them once and then import them.
CSS class nesting makes it simple to target DOM elements and saves time. It's also a lot easier to alter CSS files due to nesting.
Disadvantages: - Preprocessing tools are required for preprocessors. The time they take to recompile can be lengthy.缺点: - 预处理器需要预处理工具。它们重新编译所需的时间可能很长。
Although the source files may be small, the output CSS may be large, causing the request to take longer to finish.
Choosing a preprocessor comes down to personal choice, and it might be instructive to see how a developer could choose one over the other for your project.选择预处理器取决于个人偏好,了解开发者如何为您的项目选择其中之一可能具有教育意义。
Useful Preparation Resources:
有用的备考资源:
OOPs
面向对象编程
OS
操作系统
SQL
SQL
Practice Problems
练习题
630. What makes a block-level element different from an inline element in HTML?
HTML中块级元素与内联元素有何不同?
- 知识点: 前端 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b6c | 官方: 否 | 付费: 否
答案:
| Block 块级 | Inline 内联 |
|---|---|
| A block-level element is drawn as a block that will always start on a new line and will stretch to occupy the full width available to it, i.e. the width of its container. Examples of block-level elements by default: , , , , . 块级元素被绘制为一个块,总是从新行开始,并会拉伸以占据其可用的全部宽度,即其容器的宽度。默认情况下的块级元素示例:、、、、。 | Inline items are drawn where they are defined and take up only the space that is required. Looking at how text flows on a page is the simplest approach to understand how they work. Examples of inline elements by default: , , , , . 内联元素在其定义的位置绘制,仅占用所需的空间。观察文本在页面上的流动方式是理解它们工作原理的最简单方法。默认情况下的内联元素示例:、、、、。 |
631. 从零开发一个项目需要哪些技术与技能?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / 系统设计/架构 / UI/UX 设计 (主题: system-design;标签: frontend, backend, frameworks, database, server, ux-ui)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 695cc0361da553795622a8a0 | 官方: 是 | 付费: 否
答案:
TL;DR需要掌握前端、设计、后端语言、框架、数据库与服务器等能力,才能完整从零构建项目。
资深全栈开发者从零开发项目通常需要以下技能:
前端技术:HTML(HTML) 、CSS(CSS) 、JavaScript(JavaScript) ,以及 Angular(Angular) 、ReactJS(ReactJS) 、jQuery(jQuery) 等库。
设计能力:理解 UX/UI(UX/UI) 对构建可用产品很重要。
后端语言:熟悉 C++(C++) 、C#(C#) 、Java(Java) 、Python(Python) 、Ruby(Ruby) 、PHP(PHP) 等。
框架:例如 Spring Boot(Spring Boot) 、Django(Django) 、Ruby on Rails(Ruby on Rails) 等。
数据库技术:掌握 MySQL(MySQL) 、Oracle(Oracle) 、SQLite(SQLite) 、MongoDB(MongoDB) 等 DBMS(DBMS) 。
服务器:了解 Apache(Apache) 、NGINX(NGINX) 等服务器,便于管理与部署。
632. What is an application server, and how does it work?
如何处理浏览器兼容性问题?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006d1 | 官方: 是 | 付费: 否
答案:
An application server is a specialized software that provides a runtime environment and middleware for running enterprise-level applications. It handles the communication between the user interface, application logic, and data storage layers of an application.It provides the business logic behind any application.
应用服务器是一种专门软件,为运行企业级应用提供运行时环境和中间件。它处理用户界面、应用逻辑和数据存储层之间的通信。它提供任何应用背后的业务逻辑。
When a client first makes a request, it goes to the web server, which sends it to the application server. The application server requests the information from the database server and sends it back to the web server. The web server sends the information to the client.
当客户端首次发出请求时,请求会到达Web服务器,由Web服务器将其发送到应用服务器。应用服务器从数据库服务器请求信息并将其返回给Web服务器。Web服务器再将信息发送给客户端。
633. How do you optimize SQL queries?
你如何优化SQL查询?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006d5 | 官方: 是 | 付费: 否
答案:
Optimizing SQL queries means identifying the most effective techniques to enhance SQL query performance. Here are the most effective ways to optimize queries.
优化SQL查询意味着识别最有效的技术来提升SQL查询性能。以下是最有效的查询优化方法。
Indexing: It helps in accessing the database quickly to find the relevant data.
索引:它有助于快速访问数据库,查找相关数据。
Use SELECT query instead of SELECT: Use SELECT query to specify the columns you need instead of SELECT to avoid unnecessary I/O operations that slow down the query.
使用SELECT查询而非SELECT:使用SELECT查询指定所需列,而非SELECT,以避免不必要的I/O操作拖慢查询速度。
Avoid too many JOINs: Use the appropriate JOIN type for your SQL query to ensure you get the desired results and minimize unnecessary processing.
避免过多JOIN操作:针对SQL查询使用合适的JOIN类型,以确保获得预期结果并最小化不必要的处理。
Use subqueries: Using a subquery instead of a JOIN can be more efficient sometimes. If you only need to retrieve data from one table based on data in another, using a subquery can be faster than using a JOIN.
使用子查询:有时使用子查询代替JOIN可以更高效。如果只需要根据另一个表中的数据从一个表中检索数据,使用子查询可能比使用JOIN更快。
Use table aliases: Table aliases can make your query easier to read and write. Use aliases for tables and columns to make your query more readable.
使用表别名:表别名能让你的查询更容易阅读和编写。为表和列使用别名,使查询更具可读性。
Optimize database design: Optimize database design by avoiding redundant data and using appropriate data types. A well-designed database can help you improve query performance.
优化数据库设计:通过避免冗余数据和使用恰当的数据类型来优化数据库设计。设计良好的数据库有助于提升查询性能。
Use Wildcards: Using wildcards helps you search the database for matching results.
使用通配符:使用通配符可以帮助你在数据库中搜索匹配的结果。
634. How do you handle browser compatibility issues?
你是如何处理浏览器兼容性问题的?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006d9 | 官方: 是 | 付费: 否
答案:
Browsers like Google Chrome, Mozilla Firefox, Safari, Microsoft Edge, etc., may interpret web code differently. As a result, a web page or application that looks and functions correctly in one browser may not work the same way in another. Here are a few tips to handle browser compatibility issues.
像Google Chrome、Mozilla Firefox、Safari、Microsoft Edge等浏览器可能会以不同的方式解释网页代码。因此,在一个浏览器中外观和功能正常的网页或应用,在另一个浏览器中可能表现不同。以下是处理浏览器兼容性问题的一些建议。
Use a CSS Reset: Different browsers have different design layouts, which can cause layout inconsistencies. A CSS reset can help by setting a common baseline for all browsers.
使用CSS重置:不同浏览器有不同的设计布局,这可能导致布局不一致。CSS重置可以通过为所有浏览器设置共同的基准来帮助解决这个问题。
Use cross-browser frameworks and libraries: Cross-browser frameworks and libraries such as jQuery, React, or Angular can help developers avoid browser-specific code and provide a consistent interface across different browsers.
使用跨浏览器框架和库:跨浏览器框架和库,如jQuery、React或Angular,可以帮助开发者避免编写特定于浏览器的代码,并在不同浏览器中提供一致的接口。
Test on multiple browsers and devices: Developers should test their websites or applications on multiple browsers, including popular ones such as Chrome, Firefox, Safari, and Edge, to check compatibility.
在多种浏览器和设备上测试:开发者应该在多种浏览器上测试他们的网站或应用,包括Chrome、Firefox、Safari和Edge等主流浏览器,以检查兼容性。
Use polyfills and shims: Polyfills and shims are code snippets that provide fallback functionality for web features not supported by some browsers. You can use libraries like Modernizr, Polyfill. io, or HTML5 Shiv to help fill in gaps in browser support.
使用polyfills和shims:Polyfills和shims是代码片段,为某些浏览器不支持的Web功能提供回退功能。你可以使用像Modernizr、Polyfill.io或HTML5 Shiv这样的库来填补浏览器支持的空白。
635. What is the difference between abstract and interface?
抽象类和接口有什么区别?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006dd | 官方: 是 | 付费: 否
答案:
- An abstract class can have abstract and non-abstract methods, but an interface can only have abstract methods.
- Variables declared in an abstract class may contain non-static and non-final variables, whereas those declared in a Java interface are only static and final.
- An abstract class can provide an implementation of an interface. On the other hand, an Interface can’t implement an abstract class.
- A Java abstract class can have public, private, and protected members, but an interface only has public members.
- An abstract class can be extended using the "extends" keyword. An interface can be implemented using the "implements" keyword.
636. Why and how do you clear floats in CSS?
在CSS中为什么以及如何清除浮动?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006e1 | 官方: 是 | 付费: 否
答案:
Using floats in CSS allows you to position elements (typically images) such that surrounding content can flow around them. However, when using floats, it may cause subsequent elements to flow around floated items, leading to undesired layout issues. Clearing floats is necessary to prevent such issues and ensure proper control of the layout.
在CSS中使用浮动允许你将元素(通常是图像)定位,使周围的内容可以环绕它们流动。然而,使用浮动时,可能会导致后续元素环绕浮动元素流动,从而引发不希望的布局问题。清除浮动是必要的,以防止此类问题并确保对布局的正确控制。
There are multiple methods to clear floats in CSS. Some common techniques include:
在CSS中有多种清除浮动的方法。一些常见技巧包括:
- Clear attribute: Use the clear CSS property, with the values left, right, both, or none, on the elements that follow the floated elements:
.element-to-clear {
.element-to-clear {
clear: both;
clear: both;
}
- Clearfix (the most common method): Apply the "clearfix" technique using a pseudo-element, which involves creating an invisible element to clear the floats. This method helps avoid adding extra markup to your HTML:
.group::after {
.group::after {
content: "";
content: "";
display: table;
display: table;
clear: both;
clear: both;
}
637. What are the main differences between process and thread?
进程和线程的主要区别是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006e5 | 官方: 是 | 付费: 否
答案:
TL;DR题目原文仅提供了对比图示。
638. How do you share code between files in JavaScript?
如何在JavaScript中在文件之间共享代码?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006e9 | 官方: 是 | 付费: 否
答案:
JavaScript allows us to share code between files by ‘imports’ and ‘exports’. We can share code written in one file with another using ‘require’ and ‘module. exports’ statements in ES5 syntax, whereas we can use ‘import’ and ‘export’ statements in ES6 syntax.
JavaScript允许我们通过“导入”和“导出”在文件之间共享代码。在ES5语法中,我们可以使用‘require’和‘module.exports’语句将一个文件中的代码与另一个文件共享,而在ES6语法中,我们可以使用‘import’和‘export’语句。
639. What is the difference between Host objects and Native objects?
宿主对象(Host objects)和原生对象(Native objects)之间有什么区别?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006ed | 官方: 是 | 付费: 否
答案:
Native objects are pre-defined objects provided by JavaScript. These objects are available to all users globally, irrespective of the machine and environment.
原生对象是JavaScript提供的预定义对象。这些对象对所有用户全局可用,与机器和环境无关。
On the other hand, host objects are environment-specific JavaScript objects, varying according to the machine environment we use.
另一方面,宿主对象是特定于环境的JavaScript对象,根据我们所使用的机器环境而变化。
640. What is the best way to remove array duplicates in ES6?
在ES6中,移除数组重复项的最佳方法是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006f1 | 官方: 是 | 付费: 否
答案:
Using a set is the best way to remove duplicates from an array in ES6 because it only allows you to store unique values. When you convert the array to a set, it will remove any duplicate values. Then you need to convert the set back to an array with unique values.
使用Set是ES6中从数组中移除重复项的最佳方法,因为它只允许存储唯一的值。当你将数组转换为Set时,它会移除任何重复的值。然后你需要将Set转换回具有唯一值的数组。
641. What is “Strict Mode,” and how to use it in JavaScript?
什么是“严格模式”,以及如何在JavaScript中使用它?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006f5 | 官方: 是 | 付费: 否
答案:
Strict mode is a feature in JavaScript that allows us to execute the code in a restricted environment. It helps detect errors in the code that would normally get executed without any errors. We can enable strict mode by adding "use strict" at the top of the file or in the required function.
严格模式是JavaScript中的一个功能,允许我们在受限环境中执行代码。它有助于检测在正常情况下会无错误执行但在严格模式下会报错的代码错误。我们可以通过在文件顶部或所需函数中添加“use strict”来启用严格模式。
Example:
示例:
The string “use strict” at the top of the file tells the JavaScript interpreter to run the code in strict mode, which enforces stricter syntax and error handling rules. Next, we define a function called myFunction() that multiplies an undeclared variable x by 2 and returns the result. In non-strict mode, this would execute without any issues, but in strict mode, an error will be thrown because x is not declared.
文件顶部的字符串“use strict”告诉JavaScript解释器在严格模式下运行代码,这强制执行更严格的语法和错误处理规则。接下来,我们定义一个名为myFunction()的函数,它将一个未声明的变量x乘以2并返回结果。在非严格模式下,这不会出现任何问题,但在严格模式下,会抛出一个错误,因为x未声明。
642. How does database indexing work?
数据库索引是如何工作的?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006f9 | 官方: 是 | 付费: 否
答案:
Database indexing is like indexing in a book. Just like an index in a book helps us find a particular chapter or information quickly, a database index helps locate the data quickly. It reduces the number of rows or columns to be checked and quickly finds the information you are looking for when a query with a “where” clause is executed. That's how database indexing works.
数据库索引就像书中的索引。就像书中的索引帮助我们快速找到特定章节或信息一样,数据库索引有助于快速定位数据。它减少了需要检查的行数或列数,并在执行带有“where”子句的查询时快速找到你所寻找的信息。这就是数据库索引的工作原理。
643. What are filters in Vue.js?
Vue.js中的过滤器是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c87006fd | 官方: 是 | 付费: 否
答案:
A filter is a JavaScript function that allows you to apply common text formatting to dynamic data. It doesn't change the data directly but only changes the output to a browser. It takes through value, manipulates it, and displays the processed values.
过滤器是一个JavaScript函数,允许你对动态数据应用常见的文本格式化。它不会直接更改数据,而只会更改输出到浏览器的内容。它接收值,处理它,并显示处理后的值。
Filters are applied using the "pipe character (|) followed by the filter name. We can apply filters in two ways: local and global. Local filters can be used inside the component in which they are defined, whereas global filters can be used in any component.
过滤器通过使用“管道字符(|)后跟过滤器名称来应用。我们可以通过两种方式应用过滤器:局部和全局。局部过滤器可以在定义它们的组件内部使用,而全局过滤器可以在任何组件中使用。
644. Why is "this" operator inconsistent in JavaScript?
为什么“this”运算符在JavaScript中不一致?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700701 | 官方: 是 | 付费: 否
答案:
The "this" operator in JavaScript can be inconsistent because it can have different values based on where it is used. Its value is determined by how the function used is called rather than where it is declared. The value of "this" can also be changed using the call, apply, or bind functions making it difficult to predict the value of "this" in a given situation, which creates inconsistencies.
JavaScript 中的“this”运算符可能不一致,因为根据其使用位置,它的值可能不同。它的值由函数调用方式决定,而非声明位置。通过 call、apply 或 bind 函数也可以改变“this”的值,这使得在特定情况下难以预测“this”的值,从而产生不一致性。
645. What is Data Structure, and what are the different types?
什么是数据结构,有哪些不同类型?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700705 | 官方: 是 | 付费: 否
答案:
A data structure is a way of organizing and storing data (facts and figures) in a specialized format to retrieve it quickly and efficiently. Basically, there are two types of data structures:
数据结构是以专用格式组织和存储数据(事实和数字)以便快速高效检索的一种方式。基本上,有两种类型的数据结构:
Linear data structure:
线性数据结构:
- Array: A linear collection of elements of the same type.
- Stack: Elements are stored in the LIFO (a last-in, first-out) principle.
- Queue: A queue data structure is based on the FIFO (a first-in, first-out) principle.
- Linked list: It is a collection of elements, wherein each contains a reference to the next element.
Non-linear data structure:
非线性数据结构:
- Graph: A data structure that consists of vertices (nodes) and edges (links) that connects the vertices
- Trees: A hierarchical data structure wherein each node has two child nodes
646. What is the purpose of the 'main' element in HTML?
HTML 中“main”元素的用途是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700709 | 官方: 是 | 付费: 否
答案:
The 'main' element in HTML represents the core content of a document. The content within the tag should be unique and not repeated across documents, such as sidebars, navigation links, search forms, etc. The element must be used only once in the HTML file. It requires a closing tag at the end of the content.
HTML 中的“main”元素表示文档的核心内容。该标签内的内容应唯一,且不应在文档间重复,例如侧边栏、导航链接、搜索表单等。该元素必须在 HTML 文件中仅使用一次。它需要在内容末尾有结束标签。
647. What are semantic HTML tags, and why should you use them?
什么是语义化 HTML 标签,为什么应该使用它们?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c870070d | 官方: 是 | 付费: 否
答案:
Semantic HTML or semantic markup is the HTML that introduces the meaning to the webpage instead of just the presentation. For example, HTML elements such as header, footer, nav, main, article, p time, etc., are used to define the different sections and content on the page.
语义化 HTML 或语义化标记是引入网页含义而不仅仅是呈现的 HTML。例如,诸如 header、footer、nav、main、article、p time 等 HTML 元素用于定义页面上的不同部分和内容。
There are several reasons for using semantic HTML:
使用语义化 HTML 有以下几个原因:
- It helps search engines determine the importance and context of web pages.
- Semantic HTML makes it easier to maintain a website as the code is easier to understand.
- The pages built with semantic elements are more user-friendly and easier to read.
- Semantic HTML is important for search engine optimization (SEO).
648. What is Pascal String?
什么是 Pascal 字符串?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700711 | 官方: 是 | 付费: 否
答案:
A Pascal string is a data structure used to represent and manipulate text strings in some programming languages such as Pascal. In the context of full-stack development, it might not be as prominent as some other string representation methods, but it can still be encountered or used in certain situations.
Pascal 字符串是一种数据结构,用于在某些编程语言(如 Pascal)中表示和操作文本字符串。在全栈开发背景下,它可能不如某些其他字符串表示方法突出,但在特定情况下仍可能遇到或使用。
Common types of Pascal strings are
Pascal 字符串的常见类型有:
Character arrays: These are numbers, letters, special characters, etc., enclosed in a single quote.
字符数组:这些是用单引号括起来的数字、字母、特殊字符等。
String variables: The variable of string type is declared inside the var block in Turbo Pascal.
字符串变量:字符串类型的变量在 Turbo Pascal 的 var 块中声明。
Short strings: We use this string type when the total capacity remains constant.
短字符串:当总容量保持不变时,我们使用这种字符串类型。
Null terminated strings: This string type has the same structural layout as a C string.
空终止字符串:这种字符串类型与C字符串具有相同的结构布局。
AnsiStrings: This string type does not have any length limit.
AnsiStrings:这种字符串类型没有任何长度限制。
649. What is the difference between Map and WeakMap?
Map和WeakMap之间有什么区别?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700715 | 官方: 是 | 付费: 否
答案:
- A map accepts any type of value like string, boolean, number, etc., whereas a WeakMap only accepts only objects as keys.
- Maps are iterable, but WeakMaps are not.
- A “Map” has a size property, but a “WeakMap” does not have the same.
- The garbage collector doesn’t remove any key pointer from "Map," but it removes the key pointer from "WeakMap".
650. What is the main difference between a web server and an application server?
Web服务器和应用服务器之间的主要区别是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700719 | 官方: 是 | 付费: 否
答案:
- A web server is designed to handle HTTP requests and is used to serve static content such as HTML pages, images, and other files to web browsers, whereas an application server is designed to handle dynamic content and is used to serve business logic and application functionality to clients
- A web server is usually deployed in front of an application server to handle incoming web requests and serve static content, while the application server is responsible for processing dynamic requests and running business logic.
- Web servers provide a runtime environment for websites and web applications, whereas application servers provide a runtime environment for enterprise applications.
- Web servers don't support multi-threading, but the application server supports it.
651. What is the difference between JDBC and Hibernate?
JDBC和Hibernate之间有什么区别?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c870071d | 官方: 是 | 付费: 否
答案:
JDBC and Hibernate are Java technologies used for managing relational databases. Both technologies have some similarities, but they are not the same. Here is the difference between JDBC and Hibernate.
JDBC和Hibernate是用于管理关系数据库的Java技术。这两种技术有一些相似之处,但并不相同。以下是JDBC和Hibernate之间的区别。
652. How does DevOps work?
DevOps是如何工作的?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700721 | 官方: 是 | 付费: 否
答案:
DevOps is a technique that aims to build coordination to streamline software development and IT operations. It enables teams to work together to deliver software products faster and ensure better quality. The primary goal of DevOps is to increase efficiency and reduce errors.
DevOps是一种旨在建立协调机制以简化软件开发和IT运营的技术。它使团队能够协作,更快地交付软件产品并确保更高质量。DevOps的主要目标是提高效率并减少错误。
Under a DevOps model, the development and operations teams are no longer "siloed." Sometimes, the two teams are merged into a single team. The DevOps engineers work across the complete application lifecycle - from development and testing to deployment and operations. These engineers have multidisciplinary skills.
在DevOps模式下,开发团队和运营团队不再“孤立”。有时,这两个团队会合并成一个团队。DevOps工程师在完整的应用生命周期中工作——从开发和测试到部署和运营。这些工程师具备多学科技能。
653. What is the main difference between Promises and async/await in JavaScript?
JavaScript中Promises和async/await之间的主要区别是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700725 | 官方: 是 | 付费: 否
答案:
Promises provide an interface for dealing with asynchronous operations, allowing chaining of .then() and .catch() methods. Async/await is a syntactic sugar built on top of Promises that makes asynchronous code look more like synchronous code, using async functions and the await keyword.
Promises提供了处理异步操作的接口,允许链式调用.then()和.catch()方法。Async/await是基于Promises构建的语法糖,使异步代码看起来更像同步代码,使用async函数和await关键字。
654. Talk about multi-threading.
谈谈多线程。
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700729 | 官方: 是 | 付费: 否
答案:
A thread is defined as the single, sequential flow of the control within a program. It is not the program itself and cannot run on its own. In a running program, a thread may have to dig some of its resources.
线程被定义为程序内单一的顺序控制流。它不是程序本身,不能单独运行。在运行的程序中,线程可能需要分配一些自己的资源。
For example, the execution stack and program counter must belong to that thread. The code in a given thread is useful only for that particular context. A single thread has a single point of execution, i.e., only one user can manage one request at a time.
例如,执行栈和程序计数器必须属于该线程。给定线程中的代码仅对该特定上下文有用。单个线程具有单一执行点,即同一时间只有一个用户可以管理一个请求。
Multi-threading is a process that is used to improve CPU performance. Through this process, multiple users can manage the program at the same time, or the same user can manage several requests simultaneously. Multi-threading is achieved by executing several processes that the operating system supports.
多线程是一种用于提高CPU性能的过程。通过这个过程,多个用户可以同时管理程序,或者同一用户可以同时管理多个请求。多线程通过执行操作系统支持的多个进程来实现。
For example, a web browser has multi-threads running simultaneously - while you scroll through a page, you can simultaneously download an application or a document, listen to music, take a print in the background, and more.
例如,一个网络浏览器有多个线程同时运行——当你在页面中滚动时,你可以同时下载应用程序或文档、听音乐、在后台打印等等。
655. What are the most popular methods of session management in servlet?
在Servlet中,最流行的会话管理方法有哪些?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c870072d | 官方: 是 | 付费: 否
答案:
There are three main methods of session management in servlet:
Servlet中主要有三种会话管理方法:
URL Rewriting: It is a session management method in which a unique session ID is added to every URL. When the browser requests a new page, the session ID is sent back to the server. It allows the server to associate the request with a specific session.
URL重写:这是一种会话管理方法,其中每个URL都添加了唯一的会话ID。当浏览器请求新页面时,会话ID会发送回服务器。它允许服务器将请求与特定会话关联起来。
HttpSession: It is a built-in interface in Servlet used to store session data on the server side.
HttpSession:它是Servlet中内置的接口,用于在服务器端存储会话数据。
Cookies: Cookies are data sent by a servlet to a client's browser. The browser saves cookies and sends them back to the server in subsequent requests.
Cookies:Cookies是Servlet发送到客户端浏览器的数据。浏览器保存Cookies,并在后续请求中将其发送回服务器。
656. Explain the difference between synchronous and asynchronous programming.
解释同步和异步编程之间的区别。
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700731 | 官方: 是 | 付费: 否
答案:
In synchronous programming, the program execution happens in a sequential and blocking manner. This means the code lines are executed one after the other, and the program has to wait for the current operation to finish before moving on to the next one.
在同步编程中,程序执行以顺序和阻塞的方式发生。这意味着代码行一条接一条地执行,程序必须等待当前操作完成才能继续下一个操作。
On the other hand, asynchronous programming refers to a programming model where the program execution happens in a non-blocking and parallel manner. In this model, multiple tasks can run simultaneously, and the execution of one task does not depend on another.
另一方面,异步编程指的是一种程序执行以非阻塞和并行方式发生的编程模型。在这种模型中,多个任务可以同时运行,一个任务的执行不依赖于另一个任务。
657. What is the difference between Fail-Fast and Fail-Safe iterators?
快速失败和快速安全迭代器有什么区别?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700735 | 官方: 是 | 付费: 否
答案:
TL;DR题目原文仅提供了对比图示。
658. What is the event loop in JavaScript?
什么是JavaScript中的事件循环?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c870073d | 官方: 是 | 付费: 否
答案:
The event loop is a fundamental part of the JavaScript runtime environment. An event loop in JavaScript is a mechanism that executes tasks in a non-blocking manner. It continuously checks the message queue for new events to process and runs the corresponding event handlers.
事件循环是JavaScript运行时环境的基本组成部分。JavaScript中的事件循环是一种以非阻塞方式执行任务的机制。它持续检查消息队列中是否有新的待处理事件,并运行相应的事件处理程序。
It manages the execution of tasks and events, allowing the runtime to handle asynchronous operations such as network requests and file I/O without blocking the execution of other tasks.
它管理任务和事件的执行,使运行时能够处理异步操作(如网络请求和文件I/O),而不会阻塞其他任务的执行。
Example:
示例:
659. How will you prevent a bot from scraping a public API?
您将如何防止机器人抓取公共API?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700741 | 官方: 是 | 付费: 否
答案:
It's impossible to completely prevent data scraping if the data within the API is publicly accessible. However, throttling is an effective way to deter bots from scraping a public API. It can prevent a device from making a certain number of requests within a specific time.
如果API中的数据是公开可访问的,完全防止数据抓取是不可能的。然而,限流是阻止机器人抓取公共API的有效方法。它可以防止设备在特定时间内发出一定数量的请求。
Moreover, an HTTP error should be thrown on exceeding a defined number of requests. Apart from this, a good bot detection solution can identify visitors' behavior and automatically block malicious bots that show signs of web scraping.
此外,当超过定义的请求数量时,应引发HTTP错误。除此之外,一个好的机器人检测解决方案可以识别访问者的行为,并自动阻止表现出网页抓取迹象的恶意机器人。
660. Talk about connection leaks in Java and how they can be fixed.
谈谈Java中的连接泄漏以及如何修复它们。
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700745 | 官方: 是 | 付费: 否
答案:
In Java, a connection leak refers to a situation where a database connection is not properly closed after it has been used, resulting in the connection being unavailable for reuse by other parts of the application or by other applications. This can lead to a gradual depletion of available connections and eventually cause the application to fail due to a lack of resources.
在Java中,连接泄漏是指数据库连接在使用后未被正确关闭,导致该连接无法供应用程序的其他部分或其他应用程序重用的情况。这可能导致可用连接逐渐耗尽,最终因资源不足而导致应用程序失败。
To fix a connection leak in Java, you must always close database connections explicitly after use, preferably in a final block, to ensure that the connection is closed regardless of whether an exception occurs or not.
要修复Java中的连接泄漏,必须在每次使用后显式关闭数据库连接,最好在finally块中关闭,以确保无论是否发生异常,连接都能被关闭。
661. How do you create a callback in JavaScript?
如何在JavaScript中创建回调函数?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700749 | 官方: 是 | 付费: 否
答案:
JavaScript callback functions can be used synchronously and asynchronously. Callback functions are required because many actions are asynchronous, so they don't block a program or function from running until it is completed.
JavaScript回调函数可以同步和异步使用。回调函数是必要的,因为许多操作是异步的,所以它们不会阻塞程序或函数直到完成运行。
To create a callback function in JavaScript, we need to pass it as a parameter to another function and call it back when the task is completed.
要在JavaScript中创建回调函数,我们需要将其作为参数传递给另一个函数,并在任务完成时回调它。
Example:
示例:
662. What steps will you take to reduce a web application's load time?
你会采取哪些步骤来减少Web应用程序的加载时间?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c870074d | 官方: 是 | 付费: 否
答案:
The following are the most common ways to reduce the load time of web applications:
以下是减少Web应用程序加载时间的最常见方法:
- Compress and optimize the images on your web application.
- Keep your Javascript and CSS code in separate files outside the main HTML document.
- Reduce the file size of JavaScript and style sheets.
- Reduce the number of HTTP requests a web page needs to make.
- Place script references at the bottom of your HTML page.
- Reduce the number of 301 redirects.
- Enable browser caching to avoid reloading every time a user visits the page.
663. What is the Zip() function in Python?
Python中的Zip()函数是什么?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700751 | 官方: 是 | 付费: 否
答案:
Zip() is an inbuilt function in Python that takes iterable (such as lists, arrays, etc.) as input and returns a single iterator of tuples. Each tuple contains the n-th elements from each of the input iterables. The zip function combines elements from each of the iterables.
Zip()是Python中的一个内置函数,它接受可迭代对象(如列表、数组等)作为输入,并返回一个包含元组的迭代器。每个元组包含每个输入可迭代对象中的第n个元素。zip函数组合每个可迭代对象中的元素。
For example, if you have two lists [1, 2, 3,...] and [A, B, C,...], the zip function will combine them into a single list [(1, A), (2, B), (3, C),...].
例如,如果你有两个列表[1, 2, 3,...]和[A, B, C,...],zip函数会将它们组合成一个列表[(1, A), (2, B), (3, C),...]。
664. What is a deadlock in Java, and how to avoid it?
Java中的死锁是什么,如何避免它?
- 知识点: 前端 / 后端 / 数据库 / 算法与数据结构 / UI/UX 设计 (主题: javascript, typescript, react, nodejs, database, api-design;标签: Senior Full-Stack)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69646d35a9243c30c8700755 | 官方: 是 | 付费: 否
答案:
Deadlock is a situation in Java when two or more threads are trying to access the same object. It happens only in the case of multi-threading. We can avoid a deadlock situation by using the following ways.
死锁是Java中两个或多个线程试图访问同一对象时发生的情况。它只发生在多线程情况下。我们可以通过以下方式避免死锁情况。
Avoid nested locks: Avoid giving a lock to multiple threads if we have already given it to one.
避免嵌套锁:如果已经给一个线程分配了锁,就避免给多个线程分配锁。
Use lock timeouts: We can specify a time for a thread to prevent it from waiting indefinitely for a lock.
使用锁超时:我们可以为线程指定一个时间,以防止它无限期地等待锁。
Avoid Unnecessary Locks: Using locks unnecessarily can lead to a deadlock, and we should avoid it.
避免不必要的锁:不必要地使用锁可能导致死锁,我们应该避免这种情况。
Use lock escalation: Lock escalation helps convert multiple locks into fewer ones, reducing the risk of deadlocks.
使用锁升级:锁升级有助于将多个锁转换为较少的锁,从而降低死锁的风险。
665. DOM(DOM) 和 SAX(SAX) 解析器有什么不同?
- 知识点: 前端 / 编程语言基础 (主题: java, xml;标签: DOM, SAX, XML)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965e1d2fa809e6d3886aad0 | 官方: 是 | 付费: 否
答案:
答案DOM(DOM) 解析器将整个 XML(XML) 文档加载到内存来创建一棵 DOM(DOM) 模型树,这样可以更快的查找节点和修改 XML(XML) 结构,而 SAX(SAX) 解析器是一个基于事件的解析器,不会将整个 XML(XML) 文档加载到内存。由于这个原因,DOM(DOM) 比 SAX(SAX) 更快,也要求更多的内存,不适合于解析大 XML(XML) 文件。
666. 说一下 JSONP 实现原理?
- 知识点: 前端 / 操作系统与网络 (主题: javascript, web;标签: JSONP, Script Tag, Cross-Origin)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965ef9ffa809e6d3888392e | 官方: 是 | 付费: 否
答案:
答案jsonp(jsonp) 即 json+padding(json+padding) ,动态创建script(script) 标签,利用script(script) 标签的src属性可以获取任何域下的js(js) 脚本,通过这个特性(也可以说漏洞),服务器端不在返货json(json) 格式,而是返回一段调用某个函数的js(js) 代码,在src中进行了调用,这样实现了跨域。
667. React 是如何工作的?React 中的 Virtual DOM(虚拟 DOM)是如何工作的?
- 知识点: 前端 (主题: react, virtual-dom, frontend;标签: React, Virtual DOM, Diffing, Reconciliation, SPA)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69675f4afa809e6d38a91b54 | 官方: 是 | 付费: 否
答案:
答案
React 会创建一个虚拟 DOM(Virtual DOM)。当组件中的 state(状态)发生变化时,它首先会运行一个 “diffing”(差异比较)算法,用来识别虚拟 DOM 中发生了哪些变化。第二步是 reconciliation(协调/调和),它会根据 diff 的结果去更新真实 DOM(Real DOM)。
HTML DOM(文档对象模型)一直是树结构的——这是由 HTML 文档的结构所允许的。如今由于大型应用的存在,DOM 树变得非常庞大。随着我们越来越多地转向动态 Web 应用(Single Page Applications — SPAs,单页应用),我们需要不断地、频繁地去修改 DOM 树。这会带来真实的性能问题和开发痛点。
Virtual DOM(虚拟 DOM)是对 HTML DOM 的一种抽象。它很轻量,并且与浏览器特定的实现细节解耦。它并不是 React 发明的,但 React 使用它并免费提供。ReactElements(React 元素)存在于虚拟 DOM 中,它们在这里构成基础节点。一旦我们定义了这些 elements,ReactElements 就可以被渲染到 “真实” DOM 中。
每当某个 ReactComponent(React 组件)的 state(状态)发生变化时,React 的 diff(差异比较)算法就会运行并识别发生了哪些改变,然后用 diff 的结果来更新 DOM(文档对象模型)。关键点是:相比直接在常规 DOM 上做同样的事情,这样做会更快。
668. 什么是 React.createClass?
- 知识点: 前端 (主题: react, javascript, components, frontend;标签: React.createClass, ES6 Class, React.Component, constructor)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69675f4afa809e6d38a91b63 | 官方: 是 | 付费: 否
答案:
答案
React.createClass 允许我们生成组件 “classes”(类)。但在 ES6(ECMAScript 6)中,React 允许我们用 ES6 的 JavaScript class(类)来实现组件类。最终结果是一样的——我们都有一个组件类。但写法风格不同:一种使用 “自定义” 的 JavaScript 类系统(createClass),另一种使用 “原生” 的 JavaScript 类系统。
当我们使用 React 的 createClass() 方法时,会把一个对象作为参数传入。因此我们可以用 createClass 写出如下组件:
import React from 'react';
import React from 'react';
const Contacts = React.createClass({
const Contacts = React.createClass({
render() {
render() {
return (
return (
);
}
});
export default Contacts;
export default Contacts;
使用 ES6 class(类)来写同一个组件会略有不同。我们不再使用 react 库里的某个方法,而是去继承该库定义的 ES6 类:Component(组件)。
import React from 'react';
import React from 'react';
class Contacts extends React.Component {
class Contacts extends React.Component {
constructor(props) {
constructor(props) {
super(props);
super(props);
}
render() {
render() {
return (
return (
);
}
}
export default Contacts;
export default Contacts;
constructor()(构造函数)是 JavaScript class 中的一个特殊函数。每当通过 class 创建一个对象时,JavaScript 会调用 constructor()。
669. Class 组件(类组件)和函数组件(Function Component)的区别是什么?
- 知识点: 前端 (主题: react, components, frontend;标签: Class Component, Functional Component, State, Lifecycle)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676955fa809e6d38aabe60 | 官方: 是 | 付费: 否
答案:
答案
Class 组件(类组件)允许我们使用一些额外能力,比如本地 state(状态)和生命周期 hooks(钩子)。同时,为了让组件能够直接访问 store(存储),从而持有 state。
当我们的组件只是接收 props(属性)并把它们渲染到页面上时,这就是一个 “stateless component(无状态组件)”,这种场景可以使用纯函数(Pure Function)来实现。它们也被称为 dumb components(傻瓜组件)或 presentational components(展示型组件)。
结合上一题的例子,我们可以说 Booklist 组件是函数组件(Function Component),并且是无状态的(Stateless)。
BookList.js 示例:
// BookList.js
// BookList.js
import React from 'react';
import React from 'react';
const Booklist = books => (
const Booklist = books => (
-
>
- >
- {title}-{author} > {title}-{author} > )}
-
{books.map(({ title, author }) =>
> {books.map(({ title, author }) =>
)
另一方面,BookListContainer 组件是一个 class component(类组件)。
670. 什么是高阶组件(Higher-Order Component)?
- 知识点: 前端 (主题: react, hoc, frontend;标签: HOC, Code Reuse, Composition, Redux connect)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac16e | 官方: 是 | 付费: 否
答案:
答案
高阶组件(Higher-Order Component,HOC)是 React 中一种用于复用组件逻辑的高级技巧。HOC 不是 React API 的一部分,它是一种从 React 组合特性(compositional nature)中自然产生的模式。
高阶组件(Higher-Order Component,HOC)本质上是一个函数:它接收一个组件(Component),并返回一个新的组件(Component)。
HOC 允许你复用代码、逻辑以及引导/初始化的抽象(bootstrap abstraction)。HOC 在第三方 React 库中很常见,最常见的可能是 Redux 的 connect 函数。除了简单地共享工具库和组合之外,HOC 是在 React 组件(React Component)之间共享行为的最佳方式。如果你发现自己在不同地方写了大量重复逻辑,可能可以把这些代码重构成一个可复用的 HOC。
671. 什么是 Redux?
- 知识点: 前端 (主题: redux, state-management, frontend;标签: Redux, Store, Reducer, Action, Single Source of Truth)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac17f | 官方: 是 | 付费: 否
答案:
答案
Redux 的基本思想是:整个应用的状态(state)都保存在一个单一的 store 中。这个 store 本质上就是一个 JavaScript 对象(JavaScript Object)。改变 state 的唯一方式是:从应用中触发(dispatch)action(Action),然后编写 reducer(Reducer)来基于这些 action(Action)修改 state。整个 state 的变更过程都保存在 reducer(Reducer)中,并且不应该产生任何副作用(side-effects)。
Redux 基于“单一事实来源(single source of truth)”的思想:无论是 UI 状态(例如哪个 tab 处于 active)还是数据状态(例如用户 profile 详情),都在同一个地方管理。
{
first_name: 'John',
first_name: '约翰',
last_name: 'Doe',
last_name: '多伊',
age: 28
年龄: 28
}
所有这些数据都被 Redux 通过一个闭包(closure)保存在它称为 store 的结构中。Redux 也提供了创建 store 的方式,即 createStore(x)。
createStore 函数接收另一个函数 x 作为参数。这个传入的函数负责在某个时间点返回应用的状态(state),并且 state 会被持久化在 store 中。这个传入的函数被称为 reducer(Reducer)。
store 只能通过 dispatch(派发)一个 action(Action)来更新:应用 dispatch 一个 action(Action),它会被传入 reducer(Reducer);reducer(Reducer)返回一个全新的 state 实例;store 通知应用,然后应用按需重新渲染(re-render)。
一个有效的 reducer(Reducer)函数示例:
export default function reducer(state = {}, action) {
export default function reducer(state = {}, action) {
return state;
return state;
}
672. Redux Thunk 是用来做什么的?
- 知识点: 前端 (主题: redux, redux-thunk, middleware, frontend;标签: Redux Thunk, Middleware, Async Actions, applyMiddleware)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac184 | 官方: 是 | 付费: 否
答案:
答案
Redux thunk(Thunk)是一种 middleware(中间件),它允许我们编写 action creator(Action Creator):这些 action creator(Action Creator)返回的是一个函数,而不是一个 action(Action)。这个 thunk 随后可以用于:当满足某个条件时延迟 dispatch(派发)一个 action(Action)。这让我们可以处理 action(Action)的异步 dispatch(派发)。这个内部函数会接收 store 的方法(methods):dispatch(派发)和 getState 作为参数。
要启用 Redux Thunk,我们需要像下面这样使用 applyMiddleware():
import { createStore, applyMiddleware } from 'redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import thunk from 'redux-thunk';
import rootReducer from './reducers/index';
import rootReducer from './reducers/index';
// Note: this API requires redux@>=3.1.0
// 注意:此 API 需要 redux@>=3.1.0
const store = createStore(
const store = createStore(
rootReducer,
rootReducer,
applyMiddleware(thunk)
applyMiddleware(thunk)
);
673. 什么是 PureComponent(纯组件)?什么时候应该用 PureComponent(纯组件)而不是 Component(组件)?
- 知识点: 前端 (主题: react, performance, frontend;标签: PureComponent, Component, shouldComponentUpdate, Shallow Compare)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac189 | 官方: 是 | 付费: 否
答案:
答案
PureComponent(纯组件)与 Component(组件)基本一样,区别在于:PureComponent(纯组件)会为我们处理 shouldComponentUpdate 方法。当 props 或 state 发生变化时,PureComponent(纯组件)会对 props 和 state 做一次浅比较(shallow comparison)。而 Component(组件)默认不会自动比较当前 props/state 与下一次的 props/state。因此,只要 shouldComponentUpdate 被调用,组件默认就会重新渲染(re-render)。
当比较之前的 props/state 和下一次的 props/state 时,浅比较(shallow comparison)会检查:原始类型(primitives)是否具有相同的值(例如 1 等于 1,或 true 等于 true),以及对更复杂的 JavaScript 值(如 objects 和 arrays)而言引用(references)是否相同。
当我们从不去 mutate(直接修改)对象时,更推荐使用 PureComponent(纯组件) 而不是 Component(组件)。
示例:
class MyComponent extends React.PureComponent {
class MyComponent extends React.PureComponent {
render() {
render() {
returnHello World!
return你好,世界!
}
}
674. 为什么 Virtual DOM(虚拟 DOM) 比 Dirty checking(脏检查) 更高效?
- 知识点: 前端 (主题: react, virtual-dom, performance, frontend;标签: Virtual DOM, Dirty Checking, Diff, Rendering Performance)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac18e | 官方: 是 | 付费: 否
答案:
答案
在 React 中,每个组件都有 state(状态)。这个 state 有点像一个 observable(可观察对象)。本质上,React 知道什么时候需要重新渲染页面,因为它能够观察到 state 什么时候发生变化。
Dirty checking(脏检查) 比 observable(可观察对象) 更慢,因为我们必须以固定间隔轮询(poll)数据,并递归检查数据结构中的所有值。相比之下,在 state 上设置一个值会向 listener(监听器) 发出信号,表示某个 state 已经发生变化,因此 React 只需要监听 state 的变化事件并将重新渲染加入队列即可。
Virtual DOM(虚拟 DOM) 用于高效地对 DOM(文档对象模型) 进行重新渲染。这和对数据做脏检查并没有直接关系。我们可以在有或没有 dirty checking(脏检查) 的情况下使用 virtual DOM 进行重渲染。实际上,diff 算法(差异算法) 本身就是一个 dirty checker(脏检查器)。
我们的目标是只在 state 变化时才重新渲染虚拟树。因此,用 observable(可观察对象) 来检查 state 是否发生变化,是一种高效方式,可以防止不必要的重渲染——否则会导致大量不必要的树 diff(差异比较)。如果没有变化,我们什么都不做。
675. setState(设置状态) 是异步的吗?为什么 setState 在 React 中是异步而不是同步?
- 知识点: 前端 (主题: react, state, frontend;标签: setState, Async, Batching, Re-rendering)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac192 | 官方: 是 | 付费: 否
答案:
答案
setState() 操作是异步的,并且为了性能收益会被批处理(batched)。这在文档中有说明。
setState() 并不会立刻修改 this.state,而是创建一个待处理的 state 变更(pending state transition)。在调用该方法后立刻访问 this.state,可能会返回当前(旧的)值。对 setState 的调用没有同步执行的保证,并且可能会为了性能收益而被批处理。
这是因为 setState 会修改 state 并触发重新渲染(rerendering),这可能是一个昂贵的操作;如果做成同步,可能会导致浏览器无响应。因此 setState 调用既是异步的,也会被批处理,从而带来更好的 UI(用户界面) 体验与性能。
676. React 中受控组件(controlled component) 与非受控组件(uncontrolled component) 的区别是什么?
- 知识点: 前端 (主题: react, forms, frontend;标签: Controlled, Uncontrolled, ref, Form Handling)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac1b5 | 官方: 是 | 付费: 否
答案:
答案
这与有状态的 DOM 组件(表单元素)有关,区别如下:
- 受控组件(Controlled Component):它通过 props 拿到当前 value,并通过类似 onChange 的回调通知变化。父组件通过处理回调、管理自己的 state,并把新值作为 props 传回给受控组件,从而“控制”它。你也可以把它称为 “dumb component”。
- 非受控组件(Uncontrolled Component):它在内部存储自己的 state,当你需要它当前值时,通过 ref 去查询 DOM,从而获取当前值。这更像传统的 HTML。
在大多数(或全部)场景中,我们应该使用受控组件。
677. 解释一下 Redux 的组成部分。
- 知识点: 前端 (主题: redux, state-management, frontend;标签: Action, Reducer, Store, dispatch, subscribe)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69676958fa809e6d38aac1c2 | 官方: 是 | 付费: 否
答案:
答案
Redux 由以下组件(components)组成:
- Action:Action 是信息的载荷(payloads),把数据从应用发送到 store。它们是 store 唯一的信息来源。我们通过 store.dispatch() 把它们发送到 store。通常,Action 只是一个描述应用中发生了什么的对象。
- Reducer:Reducer 用于指定应用的 state 如何响应发送到 store 的 action 而发生变化。注意:Action 只描述发生了什么,但不描述应用的 state 如何变化;Reducer 决定 state 会变成什么样。
- Store:Store 是把 Action 和 Reducer 连接在一起的对象。Store 的职责包括:保存应用 state;通过 getState() 访问 state;通过 dispatch(action) 更新 state;通过 subscribe(listener) 注册监听器;通过 subscribe(listener) 返回的函数处理取消订阅(unregistering of listeners)。
需要注意的是:在 Redux 应用中我们只会有一个 store。当我们想拆分数据处理逻辑时,我们会使用 reducer composition(reducer 组合),而不是创建多个 store。
678. Presentational 组件(Presentational components)和 Container 组件(Container components)有什么区别?
- 知识点: 前端 / DevOps/云 (主题: react, javascript;标签: Presentational, Container, Flux)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696856bcfa809e6d38ba4c0e | 官方: 是 | 付费: 否
答案:
答案Presentational components 更关注“看起来怎么样”。它们通常只通过 props 接收数据与回调。这些组件很少拥有自己的 state,但如果有,通常也只是 UI state,而不是 data state。
Container components 更关注“如何工作”。这些组件为 presentational 或其它 container 组件提供数据和行为。它们会调用 Flux actions,并把这些 actions 作为回调传给 presentational components。它们通常是有状态的,因为它们作为数据源存在。
679. React 生命周期方法(lifecycle methods)有什么区别?
- 知识点: 前端 (主题: react, javascript;标签: Lifecycle, React 16.3)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696856bdfa809e6d38ba4c35 | 官方: 是 | 付费: 否
答案:
答案React 16.3+
- getDerivedStateFromProps:在调用 render() 之前立即调用,并且在每次 render 时都会调用。它用于一些少见场景:当你需要 derived state 时可使用。若你需要 derived state,值得阅读相关内容。
- componentDidMount:第一次渲染后执行,所有 AJAX 请求、DOM 或 state 更新、以及事件监听器的设置都应该在这里发生。
- shouldComponentUpdate:决定组件是否需要更新。默认返回 true。如果你确定组件在 state 或 props 更新后不需要重新渲染,可以返回 false。它是提升性能的好地方,因为可以阻止组件在接收新 prop 后重新渲染。
- getSnapshotBeforeUpdate:在渲染输出提交到 DOM 之前执行。它返回的值会被传入 componentDidUpdate()。可用于从 DOM 中捕获信息,例如滚动位置(scroll position)。
- componentDidUpdate:通常用于根据 prop 或 state 的变化更新 DOM。如果 shouldComponentUpdate() 返回 false,则不会触发。
componentWillUnmount:用于取消任何进行中的网络请求,或移除与该组件关联的所有事件监听器。
Before 16.3在 16.3 之前
- componentWillMount:在渲染前执行,用于根组件的应用级配置。
- componentDidMount:第一次渲染后执行,所有 AJAX 请求、DOM 或 state 更新、以及事件监听器的设置都应该在这里发生。
- componentWillReceiveProps:当特定 props 更新时执行,用于触发 state 的迁移(state transitions)。
- shouldComponentUpdate:决定组件是否需要更新。默认返回 true。如果你确定组件在 state 或 props 更新后不需要重新渲染,可以返回 false。它是提升性能的好地方,因为可以阻止组件在接收新 prop 后重新渲染。
- componentWillUpdate:在组件重新渲染前执行,前提是 shouldComponentUpdate() 返回 true 并确认存在 props & state 变化。
- componentDidUpdate:通常用于根据 prop 或 state 的变化更新 DOM。
- componentWillUnmount:用于取消任何进行中的网络请求,或移除与该组件关联的所有事件监听器。
680. 区分Real DOM(Real DOM)和Virtual DOM(Virtual DOM)
- 知识点: 前端 (主题: react, virtual-dom, dom;标签: Real DOM, Virtual DOM, DOM)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa214 | 官方: 是 | 付费: 否
答案:
答案DOM(DOM)Virtual DOM(Virtual DOM)1. 更新缓慢。1. 更新更快。2. 可以直接更新 HTML。2. 无法直接更新 HTML。3. 如果元素更新,则创建新 DOM(DOM)。3. 如果元素更新,则更新 JSX(JSX)。4. DOM 操作代价很高。4. DOM 操作非常简单。5. 消耗的内存较多。5. 很少的内存消耗。
681. React有什么特点?
- 知识点: 前端 (主题: react, virtual-dom, ssr;标签: Features, SSR, Data Flow)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa23f | 官方: 是 | 付费: 否
答案:
答案React的主要功能如下:
- 它使用虚拟DOM而不是真正的DOM。
- 它可以进行服务器端渲染。
- 它遵循单向数据流或数据绑定。
682. React有什么优点?
- 知识点: 前端 / 测试 (主题: react, jsx, testing;标签: Advantages, JSX, Testing)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa263 | 官方: 是 | 付费: 否
答案:
答案React的一些主要优点是:
- 它提高了应用的性能
- 可以方便地在客户端和服务器端使用
- 由于 JSX,代码的可读性很好
- React 很容易与 Meteor,Angular 等其他框架集成
- 使用 React,编写 UI 测试用例变得非常容易
683. React有哪些限制?
- 知识点: 前端 (主题: react, jsx;标签: Limitations, Library vs Framework, JSX)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa287 | 官方: 是 | 付费: 否
答案:
答案React的限制如下:
- React只是一个库,而不是一个完整的框架
- 它的库非常庞大,需要时间来理解
- 新手程序员可能很难理解
- 编码变得复杂,因为它使用内联模板和 JSX
684. 为什么浏览器无法读取JSX(JSX)?
- 知识点: 前端 (主题: react, jsx, babel;标签: JSX, Babel, Compilation)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa293 | 官方: 是 | 付费: 否
答案:
答案浏览器(Browser)只能处理 JavaScript 对象(JavaScript Object),而不能读取常规 JavaScript 对象中的 JSX(JavaScript XML)。所以为了使浏览器能够读取 JSX,首先,需要用像 Babel 这样的 JSX 转换器(JSX Transpiler)将 JSX 文件转换为 JavaScript 对象(JavaScript Object),然后再将其传给浏览器。
685. 与 ES5(ECMAScript 5)相比,React 的 ES6(ECMAScript 6)语法有何不同?
- 知识点: 前端 (主题: react, javascript, es5, es6;标签: ES5, ES6, Syntax)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa298 | 官方: 是 | 付费: 否
答案:
答案以下语法是 ES5(ECMAScript 5)与 ES6(ECMAScript 6)中的区别:
require 与 import
// ES5<br/>var React = require('react');<br/><br/>// ES6<br/>import React from 'react';// ES5<br/>var React = require('react');<br/><br/>// ES6<br/>import React from 'react';
export 与 exports
// ES5<br/>module.exports = Component;<br/><br/>// ES6<br/>export default Component;// ES5<br/>module.exports = Component;<br/><br/>// ES6<br/>export default Component;
component 和 function
// ES5<br/>var MyComponent = React.createClass({<br/> render: function() {<br/> return<br/> <h3>Hello Edureka!</h3>;<br/> }<br/>});<br/><br/>// ES6<br/>class MyComponent extends React.Component {<br/> render() {<br/> return<br/> <h3>Hello Edureka!</h3>;<br/> }<br/>}// ES5<br/>var MyComponent = React.createClass({<br/> render: function() {<br/> return<br/> <h3>Hello Edureka!</h3>;<br/> }<br/>});<br/><br/>// ES6<br/>class MyComponent extends React.Component {<br/> render() {<br/> return<br/> <h3>Hello Edureka!</h3>;<br/> }<br/>}
props
// ES5<br/>var App = React.createClass({<br/> propTypes: { name: React.PropTypes.string },<br/> render: function() {<br/> return<br/> <h3>Hello, {this.props.name}!</h3>;<br/> }<br/>});<br/><br/>// ES6<br/>class App extends React.Component {<br/> render() {<br/> return<br/> <h3>Hello, {this.props.name}!</h3>;<br/> }<br/>}// ES5<br/>var App = React.createClass({<br/> propTypes: { name: React.PropTypes.string },<br/> render: function() {<br/> return<br/> <h3>Hello, {this.props.name}!</h3>;<br/> }<br/>});<br/><br/>// ES6<br/>class App extends React.Component {<br/> render() {<br/> return<br/> <h3>Hello, {this.props.name}!</h3>;<br/> }<br/>}
state
// ES5<br/>var App = React.createClass({<br/> getInitialState: function() {<br/> return { name: 'world' };<br/> },<br/> render: function() {<br/> return<br/> <h3>Hello, {this.state.name}!</h3>;<br/> }<br/>});<br/><br/>// ES6<br/>class App extends React.Component {<br/> constructor(props) {<br/> super();<br/> this.state = { name: 'world' };<br/> }<br/> render() {<br/> return<br/> <h3>Hello, {this.state.name}!</h3>;<br/> }<br/>}// ES5<br/>var App = React.createClass({<br/> getInitialState: function() {<br/> return { name: 'world' };<br/> },<br/> render: function() {<br/> return<br/> <h3>Hello, {this.state.name}!</h3>;<br/> }<br/>});<br/><br/>// ES6<br/>class App extends React.Component {<br/> constructor(props) {<br/> super();<br/> this.state = { name: 'world' };<br/> }<br/> render() {<br/> return<br/> <h3>Hello, {this.state.name}!</h3>;<br/> }<br/>}
686. React与Angular有何不同?
- 知识点: 前端 (主题: react, angular, virtual-dom, mvc;标签: React vs Angular, MVC, Data Binding)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa29c | 官方: 是 | 付费: 否
答案:
答案主题React(React.js)Angular(Angular.js)1. 体系结构只有 MVC(Model-View-Controller)中的 View(视图)完整的 MVC(Model-View-Controller)2. 渲染可以进行服务器端渲染(Server-side Rendering)客户端渲染(Client-side Rendering)3. DOM(Document Object Model)使用 virtual DOM(虚拟文档对象模型)使用 real DOM(真实文档对象模型)4. 数据绑定单向数据绑定(Unidirectional Data Binding)双向数据绑定(Bidirectional Data Binding)5. 调试编译时调试(Compile-time Debugging)运行时调试(Runtime Debugging)6. 作者Facebook(脸书)Google(谷歌)
687. 你怎样理解“在React中,一切都是组件”这句话
- 知识点: 前端 / UI/UX 设计 (主题: react, components;标签: Components, UI, Reusability)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f2fa809e6d38baa2c1 | 官方: 是 | 付费: 否
答案:
答案组件(Component)是 React 应用 UI(User Interface,用户界面)的构建块。这些组件将整个 UI 分成小的独立并可重用的部分。每个组件彼此独立,而不会影响 UI 的其余部分。
688. 怎样解释 React 中 render()(渲染方法)的目的。
- 知识点: 前端 (主题: react, render;标签: render(), Component, Pure Function)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696859f3fa809e6d38baa2c9 | 官方: 是 | 付费: 否
答案:
答案每个 React 组件(Component)强制要求必须有一个 render()(渲染方法)。它返回一个 React 元素(React Element),是原生 DOM(Document Object Model)组件的表示。如果需要渲染多个 HTML(HyperText Markup Language)元素,则必须将它们组合在一个封闭标签内,例如