标签搜索
全栈-03-前端-2
程序员的自留地

全栈-03-前端-2

fiora
2026-10-21 / 0 评论 / 13 阅读
本段 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 中有三种数据绑定类型:
  1. 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.

    1. 插值:这是一种单向绑定,允许我们将数据属性的值嵌入到 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 flowTwo-way data binding
DefinitionData flows only from parent to child components.
Data flows between parent and child components in both directions.
SyntaxData is passed down from parent to child components through props.
Data is bound to form input elements using the ‘v-model’ directive.
Example
Benefits1. 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-ifv-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大家庭

Scaler.com

Scaler.com




  • 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 page

    HTML5 包含五个支持媒体的元素,如下:- :用于在网页中嵌入音频文件
  • : 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:

示例:
A 6-month online career accelerator programScaler Academy
一个为期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 => (
    >
      {books.map(({ title, author }) => > {books.map(({ title, author }) =>
    • >
    • {title}-{author} > {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() {
return
Hello 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)元素,则必须将它们组合在一个封闭标签内,例如

、、
等。此函数必须保持纯净,即必须每次调用时都返回相同的结果。

689. 你了解 Virtual DOM(虚拟文档对象模型)吗? 解释一下它的工作原理。

  • 知识点: 前端 (主题: react, virtual-dom, diffing;标签: Virtual DOM, Diff, DOM Update)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696859f3fa809e6d38baa2ce | 官方: 是 | 付费: 否

答案:

答案Virtual DOM(虚拟文档对象模型)是一个轻量级的 JavaScript 对象(JavaScript Object),它最初是 real DOM(真实文档对象模型)的副本。它是一个节点树(Node Tree),它将元素、它们的属性和内容作为对象及其属性。React 的渲染函数(Render Function)从 React 组件(Component)中创建一个节点树,然后它响应数据模型(Data Model)中的变化更新该树,这变化要么由用户输入或系统完成的各种动作引起的。
Virtual DOM(虚拟文档对象模型)工作过程有三个简单的步骤。

  • 每当底层数据发生改变时,整个 UI 都将在 Virtual DOM 描述中重新渲染。
  • 然后计算之前 DOM 表示与新表示之间的差异。
  • 完成计算后,将只用实际更改的内容更新 real DOM。
    图中内容识别:Browser(浏览器)、Virtual DOM(虚拟文档对象模型)、Real DOM(真实文档对象模型)、compare(比较)、Real DOM (updated)(更新后的真实文档对象模型)。

690. 如何将两个或多个组件嵌入到一个组件中?

  • 知识点: 前端 (主题: react, components, reactdom;标签: Composition, ReactDOM.render, Nested Components)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696859f4fa809e6d38baa45d | 官方: 是 | 付费: 否

答案:

答案可以通过以下方式将组件嵌入到一个组件中:
class MyComponent extends React.Component{<br/> render(){<br/> return(<br/> <div><br/> <h1>Hello</h1><br/> <Header/><br/> </div><br/> );<br/> }<br/>}<br/><br/>class Header extends React.Component{<br/> render(){<br/> return<br/> <h1>Header Component</h1><br/> ;<br/> }<br/>}<br/><br/>ReactDOM.render(<br/> <MyComponent/>, document.getElementById('content')<br/>);

class MyComponent extends React.Component{<br/> render(){<br/> return(<br/> <div><br/> <h1>Hello</h1><br/> <Header/><br/> </div><br/> );<br/> }<br/>}<br/><br/>class Header extends React.Component{<br/> render(){<br/> return<br/> <h1>Header Component</h1><br/> ;<br/> }<br/>}<br/><br/>ReactDOM.render(<br/> <MyComponent/>, document.getElementById('content')<br/>);

691. 什么是 Props(属性)?

  • 知识点: 前端 (主题: react;标签: React, Props)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cd9fa809e6d38baef6e | 官方: 是 | 付费: 否

答案:

答案Props(属性)是 React 中属性的缩写。它们只读组件,必须保持纯(Pure),即不可变。它们总是在整个应用中从父组件传递到子组件。子组件永远不能将 prop(属性)送回父组件。这有助于维护单向数据流(Unidirectional Data Flow),通常用于呈现动态生成的数据。

692. React中的状态(State)是什么?它是如何使用的?

  • 知识点: 前端 (主题: react;标签: React, State)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cd9fa809e6d38baef94 | 官方: 是 | 付费: 否

答案:

答案状态(State)是 React 组件的核心,是数据的来源,必须尽可能简单。基本上状态是确定组件呈现和行为的对象。与props(属性)不同,它们是可变的,并创建动态和交互式组件。可以通过 this.state() 访问它们。

693. 区分状态(State)和 props(属性)

  • 知识点: 前端 (主题: react;标签: React, State, Props)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cd9fa809e6d38baef9a | 官方: 是 | 付费: 否

答案:

答案条件State(状态)Props(属性)1. 从父组件中接收初始值Yes(是)Yes(是)2. 父组件可以改变值No(否)Yes(是)3. 在组件中设置默认值Yes(是)Yes(是)4. 在组件的内部变化Yes(是)No(否)5. 设置子组件的初始值Yes(是)Yes(是)6. 在子组件的内部更改No(否)Yes(是)

694. 如何更新组件的状态?

  • 知识点: 前端 (主题: react;标签: React, setState)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cdbfa809e6d38baf13d | 官方: 是 | 付费: 否

答案:

答案可以用 this.setState() 更新组件的状态(State)。
class MyComponent extends React.Component{

class MyComponent extends React.Component{
constructor(){
constructor(){
super();
super();
this.state = {
this.state = {
name: 'Maxx',
name: 'Maxx',
id:'101'
id:'101'
}
}
render(){
render(){
setTimeout(()=>{this.setState({name:'Jaeha', id:'222'})},2000)
setTimeout(()=>{this.setState({name:'Jaeha', id:'222'})},2000)
return (
return (
>

Hello {this.state.name}

>

Hello {this.state.name}

Your Id is {this.state.id}

>

Your Id is {this.state.id}


);
}
}

ReactDOM.render(

ReactDOM.render(
<MyComponent/>, document.getElementById('content')
<MyComponent/>, document.getElementById('content')
);//General way
);//General way
render(){
render(){
return(
return(


);
}

//With Arrow Function

//使用箭头函数
render(){
render(){
return(
return(
this.handleOnChange(e)} />
this.handleOnChange(e)} />
);
}

695. React 中的箭头函数(Arrow Function)是什么?怎么用?

  • 知识点: 前端 (主题: react;标签: React, Arrow Function)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cdbfa809e6d38baf164 | 官方: 是 | 付费: 否

答案:

答案箭头函数(=>)是用于编写函数表达式(Function Expression)的简短语法。这些函数允许正确绑定组件的上下文(Context),因为在 ES6 中默认不能使用自动绑定。使用高阶函数(Higher-Order Function)时,箭头函数非常有用。

696. 区分有状态(Stateful)和无状态(Stateless)组件。

  • 知识点: 前端 (主题: react;标签: React, Stateful, Stateless)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf304 | 官方: 是 | 付费: 否

答案:

答案有状态组件(Stateful Component)无状态组件(Stateless Component)1. 在内存中存储有关组件状态变化的信息1. 计算组件的内部的状态2. 有权改变状态2. 无权改变状态3. 包含过去、现在和未来可能的状态变化情况3. 不包含过去、现在和未来可能发生的状态变化情况4. 接受无状态组件状态变化要求的通知,然后将 props(属性)发送给他们。4. 从有状态组件接收 props(属性)并将其视为回调函数(Callback Function)。

697. React中的事件(Event)是什么?

  • 知识点: 前端 (主题: react;标签: React, Events)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf32c | 官方: 是 | 付费: 否

答案:

答案在 React 中,事件(Event)是对鼠标悬停、鼠标单击、按键等特定操作的触发反应。处理这些事件类似于处理 DOM 元素中的事件。但是有一些语法差异,如:

  • 用驼峰命名法对事件命名而不是仅使用小写字母。
  • 事件作为函数而不是字符串传递。
    事件参数里包含一组特定于事件的属性。每个事件类型都包含自己的属性和行为,只能通过其事件处理程序(Event Handler)访问。

698. 如何在React中创建一个事件?

  • 知识点: 前端 (主题: react;标签: React, Events, onClick)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf355 | 官方: 是 | 付费: 否

答案:

答案class Display extends React.Component({
show(evt) {

show(evt) {
// code
// 代码
},
render() {
render() {
// Render the div with an onClick prop (value is a function)
// 用onClick属性渲染div(值为一个函数)
return (
return (
Click Me!
点击我!

);
}
});

699. React中的合成事件(SyntheticEvent)是什么?

  • 知识点: 前端 (主题: react;标签: React, Synthetic Events)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf37f | 官方: 是 | 付费: 否

答案:

答案合成事件(SyntheticEvent)是围绕浏览器原生事件(Native Event)充当跨浏览器包装器(Wrapper)的对象。它们将不同浏览器的行为合并为一个 API(Application Programming Interface)。这样做是为了确保事件在不同浏览器中显示一致的属性。

700. 你对 React 的 refs(References)有什么了解?

  • 知识点: 前端 (主题: react;标签: React, Refs)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf385 | 官方: 是 | 付费: 否

答案:

答案Refs(References)是 React 中引用的简写。它是一个有助于存储对特定的 React 元素(Element)或组件的引用的属性,它将由组件渲染配置函数(Render Function)返回。用于对 render() 返回的特定元素或组件的引用。当需要进行 DOM(Document Object Model)测量或向组件添加方法时,它们会派上用场。

701. 列出一些应该使用 Refs(References)的情况。

  • 知识点: 前端 (主题: react;标签: React, Refs, DOM)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf38d | 官方: 是 | 付费: 否

答案:

答案以下是应该使用 refs(References)的情况:

  • 需要管理焦点、选择文本或媒体播放时
  • 触发式动画
  • 与第三方 DOM 库集成

702. 什么是高阶组件(HOC,Higher-Order Component)?

  • 知识点: 前端 (主题: react;标签: React, HOC)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf394 | 官方: 是 | 付费: 否

答案:

答案高阶组件(HOC,Higher-Order Component)是重用组件逻辑的高级方法,是一种源于 React 的组件模式。HOC 是自定义组件,在它之内包含另一个组件。它们可以接受子组件提供的任何动态,但不会修改或复制其输入组件中的任何行为。你可以认为 HOC 是“纯纯(Pure)”组件。

703. 你能用HOC(Higher-Order Component)做什么?

  • 知识点: 前端 (主题: react;标签: React, HOC)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cddfa809e6d38baf39c | 官方: 是 | 付费: 否

答案:

答案HOC(Higher-Order Component)可用于许多任务,例如:

  • 代码重用,逻辑和引导抽象
  • 渲染劫持
  • 状态抽象和控制
  • Props 控制

704. 如何模块化 React 中的代码?

  • 知识点: 前端 (主题: react;标签: React, Module, import/export)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69685cdefa809e6d38baf3c7 | 官方: 是 | 付费: 否

答案:

答案可以使用 export(导出)和 import(导入)属性来模块化代码。它们有助于在不同的文件中单独编写组件。
//ChildComponent.jsx

//ChildComponent.jsx
export default class ChildComponent extends React.Component {
export default class ChildComponent extends React.Component {
render() {
render() {
return (
return (
>

This is a child component

>

这是一个子组件


);
}
}

//ParentComponent.jsx

//ParentComponent.jsx
import ChildComponent from './childcomponent.js';
import ChildComponent from './childcomponent.js';
class ParentComponent extends React.Component {
class ParentComponent extends React.Component {
render() {
render() {
return (
return (
>
>

);
}
}

705. relative、fixed、absolute、static 定位元素有什么区别?

  • 知识点: 前端 (主题: css;标签: position)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696eef3eb43a3b362ff54900 | 官方: 是 | 付费: 否

答案:

答案定位元素是指其计算后的 position(定位)属性为 relative(相对定位)、absolute(绝对定位)、fixed(固定定位)或 sticky(粘性定位)的元素。

  • static:默认值;元素按正常文档流布局。top/right/bottom/left 和 z-index 不生效。
  • relative:相对自身原本位置偏移,不改变布局(原位置仍保留空隙)。
  • absolute:脱离文档流;相对最近的已定位祖先元素定位(若没有则相对初始包含块)。绝对定位盒子可以有外边距,且外边距不会与其他外边距折叠;它不会影响其他元素的位置。
  • fixed:脱离文档流;相对视口定位,滚动时不会移动。
  • sticky:relative 与 fixed 的混合;在未越过某个阈值前表现为 relative,越过阈值后表现为 fixed。

706. 有哪些方式可以把内容视觉上隐藏,但仍让屏幕阅读器可访问?(display vs visibility)

  • 知识点: 前端 (主题: css, accessibility;标签: a11y, visibility, screen-reader)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696eef3eb43a3b362ff54903 | 官方: 是 | 付费: 否

答案:

答案这些技巧与可访问性(a11y,Accessibility)相关。

  • visibility: hidden:元素仍在页面流中,仍占据空间。
  • width: 0; height: 0:让元素在屏幕上不占空间,从而不显示。
  • position: absolute; left: -99999px:把元素定位到屏幕外。
  • text-indent: -9999px:只对块级元素内的文本有效。
  • 元数据:例如使用 Schema.org、RDF、JSON-LD。
  • WAI-ARIA:W3C 的技术规范,用于提升网页可访问性。
    即使 WAI-ARIA(Accessible Rich Internet Applications) 是理想方案,我也会选择绝对定位(absolute positioning) 的方式,因为限制最少、适用于大多数元素且实现简单。

707. 有哪些清除浮动(clearing floats) 的方法?在什么场景下使用?

  • 知识点: 前端 (主题: css;标签: float, clearfix, clear)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696eef40b43a3b362ff54b0f | 官方: 是 | 付费: 否

答案:

答案在大型项目中,我会写一个工具类 .clearfix(clear fix) ,并在需要时使用。
overflow: hidden(溢出隐藏) 可能会在子元素高度超过父元素时裁剪内容,不太理想。
Question: 如何清除浮动元素(floated elements) 一侧的影响?
Answer: 如果你清除元素的一侧,该侧就不会接受浮动元素。把 clear 设为 left 时,元素会被移动到任何左浮动元素(left-floated elements) 的下方。clear 用于阻止元素围绕浮动元素进行环绕。
Question: 如何解决“浮动点(floated points)不会撑起父元素高度”的问题?
Answer: 你可以在一个空 div(division) 中使用 clear: both(清除双侧浮动) ,例如
;也可以使用 overflow hidden(溢出隐藏) 或 scroll(滚动) ;还可以让父元素也浮动。
What the heck? Sorry. 如果你没看懂这个问题或答案,请阅读 css-tricks(CSS 技巧网站) 的 “Techniques for clearing floats”(清除浮动技术) / all about floats(关于浮动的全部内容) 。

708. resetting(重置) 和 normalizing(规范化) CSS(层叠样式表) 有什么区别?你会选哪个,为什么?

  • 知识点: 前端 (主题: css;标签: reset, normalize)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef073b43a3b362ff56f22 | 官方: 是 | 付费: 否

答案:

答案Resetting(重置):用于移除元素的所有浏览器默认样式。例如把所有元素的 margin(外边距) 、padding(内边距) 、font-size(字体大小) 等都重置为一致。你需要重新声明常见排版元素的样式。
Normalizing(规范化):保留有用的默认样式,而不是把一切“去样式化”。它也会修复常见浏览器依赖问题导致的 bug(缺陷) 。
当我有非常定制化或不常规的网站设计,需要大量自定义样式,并且不需要保留任何默认样式时,我会选择 resetting(重置) 。

709. 请描述浮动(float) 以及它是如何工作的。

  • 知识点: 前端 (主题: css;标签: float, clearfix, clear)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef073b43a3b362ff56f25 | 官方: 是 | 付费: 否

答案:

答案float(浮动) 是一种 CSS(层叠样式表) 定位属性。浮动元素仍属于页面流(page flow) 的一部分,并会影响其他元素的位置(例如文本会围绕浮动元素流动);这不同于 position: absolute(绝对定位) ,它会脱离文档流(document flow) 。 CSS 的 clear(清除) 属性可用于让元素位于左/右/两侧浮动元素的下方。 如果一个父元素里只有浮动元素,它的高度会塌陷为 0。可以通过在容器内浮动元素之后、容器结束标签之前清除浮动来修复。 .clearfix(清除浮动类) 这种 hack(技巧) 使用了巧妙的 CSS 伪选择器(pseudo-selector) (:after) 来清除浮动。与其在父元素上设置 overflow(溢出) ,不如给父元素额外加一个 clearfix 类,然后应用以下 CSS:
.clearfix:after {

.clearfix:after {
content: ' ';
content: ' ';
visibility: hidden;
visibility: hidden;
display: block;
display: block;
height: 0;
height: 0;
clear: both;
clear: both;
}另外,也可以给父元素设置 overflow: auto 或 overflow: hidden,这会在子元素内部建立新的块级格式化上下文(BFC,Block Formatting Context),从而父元素会扩展以包含其子元素。

710. 请描述 z-index,以及堆叠上下文(stacking context)是如何形成的。

  • 知识点: 前端 / 算法与数据结构 (主题: css;标签: z-index, stacking-context)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef073b43a3b362ff56f28 | 官方: 是 | 付费: 否

答案:

答案CSS 的 z-index 属性控制重叠元素的垂直堆叠顺序。z-index 只影响 position(定位)不是 static 的元素。
如果没有任何 z-index 值,元素会按它们在 DOM(Document Object Model)中出现的顺序堆叠(同一层级中更靠后的元素会显示在更上层)。
具有非 static 定位的元素(及其子元素)会始终显示在默认 static 定位元素的上方,而不受 HTML(HyperText Markup Language)层级影响。
堆叠上下文(stacking context)是包含一组层(layers)的元素。在某个局部堆叠上下文内,子元素的 z-index 是相对于该上下文元素计算的,而不是相对于文档根(document root)。
该上下文之外的层——也就是局部堆叠上下文的兄弟元素——不能插入到其内部层之间。如果元素 B 在元素 A 之上,那么 A 的子元素 C 即使 z-index 比 B 更高,也不可能高于 B。
每个堆叠上下文都是自包含的——当元素内容完成堆叠后,整个元素会作为一个整体参与父级堆叠上下文的堆叠顺序。一些 CSS 属性会触发新的堆叠上下文,例如 opacity(不透明度)小于 1、filter(滤镜)不是 none、transform(变换)不是 none。

711. 解释 CSS sprites(精灵图),以及你会如何在页面或站点中实现它。

  • 知识点: 前端 (主题: css;标签: sprites, http-requests, background-position)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef1cdb43a3b362ff5b84c | 官方: 是 | 付费: 否

答案:

答案CSS sprites(精灵图)将多张图片合并成一张更大的图片。这是图标常用的一种技术(Gmail 使用它)。如何实现:

  • 使用 sprite 生成器,把多张图片打包成一张,并为其生成对应的 CSS。
  • 为每张小图定义对应的 CSS class,设置 background-image、background-position、background-size 等属性。
  • 使用时,把对应的 class 加到元素上。
    优势:
  • 减少多张图片的 HTTP 请求数量(每个 spritesheet 只需要一次请求)。但在 HTTP2 下,同时加载多张图片已经不再是很大的问题。
  • 可以提前下载那些“在需要时才会显示”的资源,例如仅在 :hover pseudo-states 出现的图片,这样不会出现闪烁。

712. 你会如何处理浏览器特定的样式问题?

  • 知识点: 前端 (主题: css;标签: cross-browser, autoprefixer, normalize)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef1d1b43a3b362ff5ba54 | 官方: 是 | 付费: 否

答案:

答案- 定位问题以及出问题的浏览器之后,使用只在该浏览器下加载的独立样式表。不过这种方式需要服务端渲染(server-side rendering)支持。

  • 使用像 Bootstrap 这类已经帮你处理兼容问题的库。
  • 使用 autoprefixer 自动为代码添加 vendor prefixes。
  • 使用 Reset CSS 或 Normalize.css。

713. 你如何为功能受限的浏览器提供页面?你会使用哪些技术/流程?

  • 知识点: 前端 (主题: css;标签: progressive-enhancement, graceful-degradation, modernizr, caniuse)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef1d4b43a3b362ff5bc6c | 官方: 是 | 付费: 否

答案:

答案- Graceful degradation(优雅降级):为现代浏览器构建应用,同时确保在旧浏览器中仍可用。

  • Progressive enhancement:先构建基础可用的体验,当浏览器支持时再逐步增强功能。
  • 使用 caniuse.com 检查特性支持情况。
  • 使用 Autoprefixer 自动插入 vendor prefix。
  • 使用 Modernizr 做特性检测(feature detection)。
  • 使用 CSS Feature queries @support

714. 使用 CSS 预处理器(preprocessor)有哪些优点/缺点?

  • 知识点: 前端 / 操作系统与网络 (主题: css;标签: preprocessor, sass, less)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef841b43a3b362ff6730c | 官方: 是 | 付费: 否

答案:

答案优点:

  • CSS 更易维护。
  • 更容易编写嵌套选择器。
  • 使用变量实现一致的主题;可以在不同项目间共享主题文件。
  • 使用 mixins 生成重复的 CSS。
  • 可以把代码拆分到多个文件中。CSS 文件也能拆分,但那会需要为每个 CSS 文件发起一次 HTTP 请求来下载。
    缺点:
  • 需要预处理工具;重新编译时间可能较慢。

715. 描述你使用过的 CSS 预处理器(CSS preprocessor)有哪些喜欢和不喜欢的地方。

  • 知识点: 前端 / 操作系统与网络 (主题: css;标签: preprocessor, sass, less)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef841b43a3b362ff67314 | 官方: 是 | 付费: 否

答案:

答案喜欢:

  • 基本上就是上面提到的那些优点。
  • Less 是用 JavaScript 编写的,这与 Node 配合得很好。
    不喜欢:
  • 我通过 node-sass 使用 Sass;node-sass 是用 C++ 编写的 LibSass 的绑定。我在不同 node 版本之间切换时,经常需要重新编译它。
  • 在 Less 中,变量名以 @ 开头,容易与原生 CSS 关键字(如 @media、@import、@font-face 规则)混淆。

716. 解释浏览器如何判断哪些元素匹配某个 CSS 选择器(CSS selector)。

  • 知识点: 前端 (主题: css;标签: selector-matching, performance, key-selector)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef841b43a3b362ff6731b | 官方: 是 | 付费: 否

答案:

答案这部分与上面“编写高效 CSS”的内容相关。浏览器从最右侧(关键选择器(key selector))向左匹配选择器。浏览器会先根据关键选择器在 DOM(Document Object Model)中筛选元素,再向上遍历其父元素(parent element)来判断是否匹配。选择器链(selector chain)越短,浏览器越快判断该元素是否匹配该选择器。
例如选择器 p span,浏览器会先找到所有 元素,然后沿着其父元素一路向上遍历到根节点(root node)以寻找

元素。对于某个特定的 ,一旦找到一个

,它就知道该 匹配,并且可以停止匹配。

717. 解释你对盒模型(box model)的理解,以及你会如何在 CSS 中告诉浏览器用不同盒模型渲染布局。

  • 知识点: 前端 (主题: css;标签: box-model, padding, border, margin)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bdc | 官方: 是 | 付费: 否

答案:

答案CSS 盒模型(box model)描述了文档树(document tree)中元素生成的矩形盒子,并按照可视化格式化模型(visual formatting model)进行布局。每个盒子都有内容区域(content area)(例如文本、图片等),以及可选的外层 padding、border 和 margin 区域。
CSS 盒模型负责计算:

  • 块级元素占据多少空间。
  • border 和/或 margin 是否重叠或折叠。
  • 盒子的尺寸。
    盒模型有如下规则:
  • 块级元素的尺寸由 width、height、padding、border 和 margin 共同计算。
  • 如果未指定 height,块级元素的高度等于其内容高度再加上 padding(除非存在浮动,见下文)。
  • 如果未指定 width,未浮动的块级元素会扩展以适配其父元素的宽度(减去 padding)。
  • 元素的 height 由内容的高度计算。
  • 元素的 width 由内容的宽度计算。
  • 默认情况下,padding 和 border 不计入元素的 width 和 height。

718. 你在本地或生产环境中用过哪些 CSS 框架(CSS framework)?你会如何修改/改进它们?

  • 知识点: 前端 (主题: css;标签: bootstrap, semantic-ui, bulma, framework)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bed | 官方: 是 | 付费: 否

答案:

答案- Bootstrap:发布周期慢。Bootstrap 4 几乎 2 年都处于 alpha。可以新增 spinner button 组件,因为它很常用。

  • Semantic UI:源码结构让主题定制非常难理解;它的非传统 theming 系统很难定制;在 vendor 库中硬编码了 config 路径;不像 Bootstrap 那样为覆盖变量而设计得很好。
  • Bulma:需要大量非语义且多余的 class 和 markup;不向后兼容;升级版本会以很隐蔽的方式破坏应用。

719. 你试用过新的 CSS Flexbox 或 Grid 规范吗?

  • 知识点: 前端 (主题: css;标签: flexbox, grid, flex-grow, safari)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bf0 | 官方: 是 | 付费: 否

答案:

答案是的。Flexbox 主要用于一维布局,而 Grid 用于二维布局。

  • Flexbox 解决了很多常见的 CSS 问题,例如容器内垂直居中、sticky footer 等。Bootstrap 和 Bulma 都基于 Flexbox,它可能是现在推荐的布局方式。我之前尝试过 Flexbox,但在使用 flex-grow 时遇到一些浏览器兼容问题(Safari),不得不用 inline-block 和数学计算百分比宽度来重写代码,体验并不友好。
  • Grid 是创建网格布局最直观的方法(最好是这样!),但目前浏览器支持还不够广泛。

720. 响应式设计(responsive design)与自适应设计(adaptive design)有什么不同?

  • 知识点: 前端 / UI/UX 设计 (主题: css;标签: responsive, adaptive, progressive-enhancement)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bf3 | 官方: 是 | 付费: 否

答案:

答案响应式与自适应设计都试图在不同设备上优化用户体验,针对不同视口尺寸(viewport size)、分辨率(resolution)、使用场景、控制方式等进行调整。
响应式设计(Responsive Design)基于“灵活性”原则——一个流式网站可以在任何设备上看起来都不错。响应式网站使用媒体查询(Media Queries)、弹性网格(Fluid Grids)和响应式图片(Responsive Images),创建一个会基于多种因素而伸缩变化的用户体验,就像一个球变大或变小以穿过多个不同大小的圈。
自适应设计(Adaptive Design)更像现代意义上的渐进增强(Progressive Enhancement)。它不是一个灵活的设计,而是检测设备及其他特性,然后基于预定义的一组视口尺寸和其他特征提供合适的功能与布局。网站检测所用设备类型,并为该设备提供预设布局。不是一个球穿过多个不同大小的圈,而是根据圈的大小使用多个不同的球。

721. 你做过 Retina 图形相关工作吗?如果有,什么时候做的,用了哪些技术?

  • 知识点: 前端 (主题: css;标签: retina, devicePixelRatio, svg, icon-font)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bf7 | 官方: 是 | 付费: 否

答案:

答案我倾向于使用更高分辨率的图形(显示尺寸的两倍)来处理 Retina 显示(Retina Display)。
更好的方式是使用类似 @media only screen and (min- device-pixel- ratio: 2) { ... } 的媒体查询(Media Query),并更换 background-image。
对于图标,我也会尽量使用 SVG(Scalable Vector Graphics)和 icon fonts(图标字体),因为它们无论分辨率如何都能渲染得非常清晰。
另一种方法是用 JavaScript 在检查 window.devicePixelRatio 值后,把 的 src 属性替换为更高分辨率版本。

722. 有没有理由用 translate() 代替 absolute positioning(绝对定位),或反过来?为什么?

  • 知识点: 前端 (主题: css;标签: translate, transform, reflow, repaint, gpu)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bfa | 官方: 是 | 付费: 否

答案:

答案- translate() 是 CSS transform(变换)的一个值。改变 transform 或 opacity(不透明度)不会触发浏览器 reflow(回流)或 repaint(重绘),但会触发 compositing(合成);而改变 absolute positioning 会触发 reflow。transform 会让浏览器为元素创建 GPU layer(GPU图层),而改变 absolute positioning 属性使用的是 CPU(中央处理器)。因此 translate() 更高效,能带来更短的绘制时间,从而让动画更顺滑。

  • 使用 translate() 时,元素仍会占据其原本空间(有点像 position: relative),不同于改变 absolute positioning。

723. 什么是 shadow DOM(影子DOM)?

  • 知识点: 前端 (主题: css, web-components;标签: shadow-dom, polymer)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696ef9b0b43a3b362ff69bfe | 官方: 是 | 付费: 否

答案:

答案把 DOM 的一部分进行封装(encapsulate)。隐藏子树(subtree)。你可以在不同的 shadow DOM 里使用相同的 ID。Polymer 使用它。这样你的 DOM 就变得可复用。如果面试官对你的回答不满意,就把链接给他,让他周末花时间读一读。

724. 描述伪元素(pseudo-elements),并讨论它们的用途。

  • 知识点: 前端 (主题: css;标签: pseudo-elements, before, after, first-line, first-letter)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f1120120fcc1591157ce4 | 官方: 是 | 付费: 否

答案:

答案CSS 伪元素(Pseudo-elements)是添加到选择器上的关键字,它可以让你为被选中元素的某个特定部分设置样式。它们可以用于装饰(:first-line、:first-letter),也可以在不修改标记(markup)的情况下,通过与 content: ... 结合来向标记中“添加元素”(:before、:after)。

  • :first-line 和 :first-letter 可用于装饰文本。
  • 如上所示,在 .clearfix hack 中使用,用于添加一个零宽空元素并设置 clear: both。
  • 工具提示(tooltips)中的三角形箭头会使用 :before 和 :after。这鼓励关注点分离,因为三角形被视为样式的一部分,而不是真正的 DOM。仅用 CSS 样式而不额外添加一个 HTML 元素,几乎无法画出一个三角形。

725. 前端框架选型常见考虑因素有哪些?AOT(Ahead-of-Time,预编译)和 JIT(Just-in-Time,即时编译)有什么区别?

  • 知识点: 前端 (主题: react, vue, javascript;标签: aot, jit, performance)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a5120fcc159116567f | 官方: 是 | 付费: 否

答案:

答案选型通常围绕包体积与响应速度(首屏/交互延迟)权衡。AOT(构建时编译)把模板/组件在构建阶段编译成高效代码,运行时更轻、更快;JIT(运行时编译)首次加载可能更慢、体积可能更大,因为运行时需要携带编译器与编译开销。

726. 为什么 Vue 更容易在编译期做静态优化,而 React JSX 更难?

  • 知识点: 前端 (主题: react, vue, javascript;标签: compiler, jsx, template, optimization)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a5120fcc1591165682 | 官方: 是 | 付费: 否

答案:

答案Vue 以模板(Template)为主,结构相对固定,编译器(Compiler)可区分静态/动态片段(Static/Dynamic Fragments)并做提升(Hoisting)、跳过等优化;而 JSX 表达能力极强,运行时逻辑可任意组合,静态分析(Static Analysis)难度高,编译期很难稳定推断“哪些依赖会变化、哪些节点可跳过”,因此更多依赖运行时调度(Runtime Scheduling)与缓存手段(如 memo(Memoization))。

727. React 为什么强调单向数据流(Unidirectional Data Flow)?Vue 为什么常被认为更“接近双向”?

  • 知识点: 前端 (主题: react, vue, javascript;标签: data-flow, v-model)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656ba | 官方: 是 | 付费: 否

答案:

答案React 从设计上推崇自上而下的数据流:状态(State)由父组件/上层持有,通过 props(Properties)下发,变更通过回调(Callback)上报,利于可预测性与调试。Vue 常见“更接近双向”来自 v-model 等机制:表单场景可将输入与状态自动同步;但本质上仍建议以单向为主,只是在语法层提供更便捷的双向绑定(Two-Way Binding)封装。

728. Vue2 与 Vue3 的响应式(Reactive)实现有什么关键变化?

  • 知识点: 前端 (主题: react, vue, javascript;标签: vue2, vue3, proxy)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656c0 | 官方: 是 | 付费: 否

答案:

答案Vue2 主要基于 Object.defineProperty 劫持 getter/setter,初始化阶段往往需要递归处理对象属性;Vue3 基于原生 Proxy,可覆盖更多数据结构与操作(如数组/删除属性),并倾向于“用到才代理”,配合 effect/依赖图(Dependency Graph)管理减少冗余 watcher,从而在可维护性与性能上更优。

729. React 为什么强调不可变数据(Immutable)?不这么做会有什么坑?

  • 知识点: 前端 (主题: react, vue, javascript;标签: immutability, state)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656c3 | 官方: 是 | 付费: 否

答案:

答案不可变数据便于浅比较(Shallow Comparison)判断更新、追踪变更来源与时间线(调试/回滚)。如果直接修改 state(State),引用不变,React 可能认为“没变化”而跳过渲染,或在依赖旧引用的逻辑中产生诡异行为。正确做法是创建新对象/新数组替换原值,或使用 Immer 等工具在保持开发体验的同时生成不可变结果。

730. 什么是“有状态组件(Stateful Component)”和“无状态组件(Stateless Component)”?在 React 中为什么更推荐函数组件(Function Component)?

  • 知识点: 前端 (主题: react, vue, javascript;标签: hooks, functional-components)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656fa | 官方: 是 | 付费: 否

答案:

答案有状态组件通常指能维护自身状态与生命周期的类组件(Class Component);无状态组件多为纯函数(Pure Function),专注展示与轻量逻辑。现代 React 推荐函数组件 + Hooks:代码更简洁、逻辑复用更自然(自定义 Hook)、避免 this 心智负担,且配合 memo(Memoization)等机制更易做性能优化。状态应尽量集中与可控,减少分散带来的维护成本。

731. 为什么两次传入 useState 的值相同,组件通常不会重新渲染?

  • 知识点: 前端 (主题: react, vue, javascript;标签: useState, bailout)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc1591165702 | 官方: 是 | 付费: 否

答案:

答案React 会对新旧 state 做一次类似 Object.is 的比较;若引用/值相同,认为没有可见变化就会跳过本次更新,这是减少无效渲染的优化。若希望触发更新,需要改变引用(如创建新对象/数组)或引入额外状态/机制表达“确实发生了变化”。

732. useEffect 的依赖数组(Dependency Array)如何工作?为什么数组/对象依赖容易“监听不到变化”?

  • 知识点: 前端 (主题: react, vue, javascript;标签: useEffect, deps, shallow-compare)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc1591165708 | 官方: 是 | 付费: 否

答案:

答案依赖比较通常是浅比较(类似 Object.is)。数组/对象即使内容变了,但如果引用不变,Effect 不会重新执行;反过来,如果每次都创建新引用,也会导致频繁触发。常见做法:保持引用稳定(useMemo/useCallback)、只依赖必要的基本类型、或在确有需要时做序列化/深比较(注意性能)。

733. useEffect 和 useLayoutEffect 有什么区别?何时该用 useLayoutEffect?

  • 知识点: 前端 (主题: react, vue, javascript;标签: useEffect, useLayoutEffect, dom)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc159116570b | 官方: 是 | 付费: 否

答案:

答案useEffect 通常在浏览器完成绘制后执行,不阻塞渲染;useLayoutEffect 在 DOM 变更提交后、浏览器绘制前同步执行,适合需要测量布局/同步读写 DOM 的场景(如读取尺寸并立刻调整)。滥用 useLayoutEffect 会阻塞绘制,影响首屏与交互。

734. React.forwardRef 和 useImperativeHandle 用来解决什么问题?

  • 知识点: 前端 (主题: react, vue, javascript;标签: forwardRef, useImperativeHandle)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc1591165714 | 官方: 是 | 付费: 否

答案:

答案函数组件(Function Component)没有实例(Instance),默认无法像类组件(Class Component)那样被 ref 直接控制。forwardRef 用于把父组件的 ref 透传到子组件内部某个 DOM/对象;useImperativeHandle 则允许子组件自定义暴露给父组件的接口(只暴露必要方法),避免父组件直接操作内部细节导致“ref 失控”。

735. Immutable.js 和 Immer 的核心区别是什么?各自适合什么场景?

  • 知识点: 前端 (主题: react, vue, javascript;标签: immutablejs, immer, structural-sharing)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc1591165717 | 官方: 是 | 付费: 否

答案:

答案Immutable.js 提供一套独立的持久化数据结构(Persistent Data Structure)与 API(List/Map/Set 等),通过结构共享(Structural Sharing)提升不可变更新效率,但有类型转换与入侵性、学习成本与体积负担。Immer 通过“写可变、产不可变”(常借助 Proxy)提供更贴近原生的开发体验,适合在不引入全套新数据结构的前提下做不可变更新。

736. useReducer 相比 useState 有什么优势?它与 Redux 的关系是什么?

  • 知识点: 前端 (主题: react, vue, javascript;标签: useReducer, redux, state)
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc159116571a | 官方: 是 | 付费: 否

答案:

答案useReducer 适合:状态逻辑复杂、多个子状态联动、下一状态依赖上一状态等场景;也便于把 dispatch 传给子组件以减少回调层层传递。它的思想与 Redux 类似(reducer + action),但没有 Redux 的中间件/全局生态;可与 Context 结合实现轻量全局状态。

737. 为什么通常建议把 CSS 的 放在 里,而把 JS 的
  • [ ]

  • [ ]

  • [ ]

839. If your app receives data from a third-party API, which HTTP response header must the server specify to allow exceptions to the same-origin policy?

如果你的应用从第三方API接收数据,服务器必须指定哪个HTTP响应头以允许同源策略的例外?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7019 | 官方: 是 | 付费: 否

答案:

  • [ ] Security-Mode
    Security-Mode

    Security-Mode
  • [x] Access-Control-Allow-Origin
    Access-Control-Allow-Origin

    Access-Control-Allow-Origin
  • [ ] Different-Origin
    Different-Origin

    Different-Origin
  • [ ] Same-Origin
    Same-Origin

    Same-Origin

840. What is the output of this code?

这段代码的输出是什么?
let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];rainForests.splice(0, 2);console.log(rainForests);
let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];rainForests.splice(0, 2);console.log(rainForests);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e701c | 官方: 是 | 付费: 否

答案:

  • [ ] ["Amazon","Borneo","Cerrado","Congo"]
    ["Amazon","Borneo","Cerrado","Congo"]

    ["Amazon","Borneo","Cerrado","Congo"]
  • [x] ["Cerrado", "Congo"]
    ["Cerrado", "Congo"]

    ["Cerrado", "Congo"]
  • [ ] ["Congo"]
    ["Congo"]

    ["Congo"]
  • [ ] ["Amazon","Borneo"]
    ["Amazon","Borneo"]

    ["Amazon","Borneo"]

841. Which missing line would allow you to create five variables(one,two,three,four,five) that correspond to their numerical values (1,2,3,4,5)?

哪一行缺失的代码可以让你创建五个变量(one、two、three、four、five),它们分别对应数值(1、2、3、4、5)?
const numbers = [1, 2, 3, 4, 5];//MISSING LINE
const numbers = [1, 2, 3, 4, 5];//缺失行
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e701f | 官方: 是 | 付费: 否

答案:

  • [x] const [one,two,three,four,five]=numbers
    const [one,two,three,four,five]=numbers

    const [one,two,three,four,five]=numbers
  • [ ] const {one,two,three,four,five}=numbers
    const {one,two,three,four,five}=numbers

    const {one,two,three,four,five}=numbers
  • [ ] const [one,two,three,four,five]=[numbers]
    const [one,two,three,four,five]=[numbers]

    const [one,two,three,four,five]=[numbers]
  • [ ] const {one,two,three,four,five}={numbers}
    const {one,two,three,four,five}={numbers}

    const {one,two,three,four,five}={numbers}

842. What will this code print?

这段代码会打印什么?
const obj = {
> 
const obj = {
  a: 1,  b: 2,  c: 3,};const obj2 = {
> a: 1,  b: 2,  c: 3,};const obj2 = {
  ...obj,  a: 0,};console.log(obj2.a, obj2.b);
...obj, a: 0,};console.log(obj2.a, obj2.b);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7022 | 官方: 是 | 付费: 否

答案:

  • [ ] Nothing, it will throw an error
    Nothing, it will throw an error

    不会打印任何内容,它会抛出错误
  • [x] 0 2
  • 2
  • [ ] undefined 2
    undefined 2

    undefined 2
  • [ ] undefined 2
    undefined 2

    undefined 2

843. Which line could you add to this code to print "jaguar" to the console?

你可以在此代码中添加哪一行来在控制台打印“jaguar”?
let animals = ['jaguar', 'eagle'];//Missing Lineconsole.log(animals.pop()); //Prints jaguar
let animals = ['jaguar', 'eagle'];//缺失行console.log(animals.pop()); //打印 jaguar
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7025 | 官方: 是 | 付费: 否

答案:

  • [ ] animals.filter(e => e === "jaguar");
    animals.filter(e => e === "jaguar");

    animals.filter(e => e === "jaguar");
  • [ ] animals.reverse();
    animals.reverse();

    animals.reverse();
  • [ ] animals.shift();
    animals.shift();

    animals.shift();
  • [x] animals.pop();
    animals.pop();

    animals.pop();

844. What line is missing from this code?

这段代码中缺少哪一行?
//Missing Linefor (var i = 0; i < vowels.length; i++) {
> 
//缺失行for (var i = 0; i < vowels.length; i++) {
  console.log(vowels[i]);  //Each letter printed on a separate line as follows;  //a  //e  //i  //o  //u}
console.log(vowels[i]); //每个字母分别打印在一行上,如下所示; //a //e //i //o //u}
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e702a | 官方: 是 | 付费: 否

答案:

  • [ ] let vowels = "aeiou".toArray();
    let vowels = "aeiou".toArray();

    let vowels = "aeiou".toArray();
  • [ ] let vowels = Array.of("aeiou");
    let vowels = Array.of("aeiou");

    let vowels = Array.of("aeiou");
  • [ ] let vowels = {"a", "e", "i", "o", "u"};
    let vowels = {"a", "e", "i", "o", "u"};

    let vowels = {"a", "e", "i", "o", "u"};
  • [x] let vowels = "aeiou";
    let vowels = "aeiou";

    let vowels = "aeiou";

845. What will be logged to the console?

什么将被记录到控制台?
const x = 6 % 2;const y = x ? 'One' : 'Two';console.log(y);
const x = 6 % 2;const y = x ? 'One' : 'Two';console.log(y);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e702e | 官方: 是 | 付费: 否

答案:

  • [ ] undefined
    undefined

    undefined
  • [ ] One
    One

    一
  • [ ] true
    true

    true
  • [x] Two
    Two

    二

846. How would you access the word It from this multidimensional array?

你将如何从多维数组中访问单词It?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7031 | 官方: 是 | 付费: 否

答案:

  • [ ] matrix[1[2]]
    matrix[1[2]]

    matrix[1[2]]
  • [x] matrix1
    matrix1

    matrix1
  • [ ] matrix[1,2]
    matrix[1,2]

    matrix[1,2]
  • [ ] matrix1
    matrix1

    matrix1

847. What does this code do?

这段代码是做什么的?
const animals = ['Rabbit', 'Dog', 'Cat'];animals.unshift('Lizard');
const animals = ['Rabbit', 'Dog', 'Cat'];animals.unshift('Lizard');
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7034 | 官方: 是 | 付费: 否

答案:

  • [x] It adds "Lizard" to the start of the animals array.
    It adds "Lizard" to the start of the animals array.

    它将“Lizard”添加到animals数组的开头。
  • [ ] It adds "Lizard" to the end of the animals array.
    It adds "Lizard" to the end of the animals array.

    它将“Lizard”添加到animals数组的末尾。
  • [ ] It replaces "Rabbit" with "Lizard" in the animals array.
    It replaces "Rabbit" with "Lizard" in the animals array.

    它将animals数组中的“Rabbit”替换为“Lizard”。
  • [ ] It replaces "Cat" with "Lizard" in the animals array.
    It replaces "Cat" with "Lizard" in the animals array.

    它将animals数组中的“Cat”替换为“Lizard”。

848. What is the output of this code?

这段代码的输出是什么?
let x = 6 + 3 + '3';console.log(x);
let x = 6 + 3 + '3';console.log(x);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7037 | 官方: 是 | 付费: 否

答案:

  • [x] 93
    93
  • [ ] 12
    12
  • [ ] 66
    66
  • [ ] 633
    633

849. Which statement can take a single expression as input and then look through a number of choices until one that matches that value is found?

哪个语句可以接受单个表达式作为输入,然后查找多个选项,直到找到与该值匹配的选项?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e703a | 官方: 是 | 付费: 否

答案:

  • [ ] else
    else

    else
  • [ ] when
    when

    when
  • [ ] if
    if

    if
  • [x] switch
    switch

    switch

850. Which statement prints "roar" to the console?

哪个语句将“roar”打印到控制台?
var sound = 'grunt';var bear = { sound: 'roar' };function roar() {
> 
var sound = 'grunt';var bear = { sound: 'roar' };function roar() {
  console.log(this.sound);}
console.log(this.sound);}
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e703d | 官方: 是 | 付费: 否

答案:

  • [ ] bear.bind(roar);
    bear.bind(roar);

    bear.bind(roar);
  • [ ] roar.bind(bear);
    roar.bind(bear);

    roar.bind(bear);
  • [x] roar.apply(bear);
    roar.apply(bear);

    roar.apply(bear);
  • [ ] bearroar;
    bearroar;

    bearroar;

851. Which choice is a valid example of an arrow function, assuming c is defined in the outer scope?

哪个选项是箭头函数的有效示例,假设 c 是在外部作用域中定义的?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7040 | 官方: 是 | 付费: 否

答案:

  • [ ] a, b => { return c; }
    a, b => { return c; }

    a, b => { return c; }
  • [ ] a, b => c
    a, b => c

    a, b => c
  • [ ] { a, b } => c
    { a, b } => c

    { a, b } => c
  • [x] { a, b } => c
    { a, b } => c

    { a, b } => c

852. Which statement correctly imports this code from some-file.js?

哪个语句正确地从 some-file.js 导入了这段代码?
//some-file.jsexport const printMe = (str) => console.log(str);
//some-file.jsexport const printMe = (str) => console.log(str);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7043 | 官方: 是 | 付费: 否

答案:

  • [ ] import printMe from './some-file';
    import printMe from './some-file';

    import printMe from './some-file';
  • [x] import { printMe } from './some-file';
    import { printMe } from './some-file';

    import { printMe } from './some-file';
  • [ ] import default as printMe from './some-file';
    import default as printMe from './some-file';

    import default as printMe from './some-file';
  • [ ] const printMe = import './some-file';
    const printMe = import './some-file';

    const printMe = import './some-file';

853. What will be the output of this code?

这段代码的输出会是什么?
const arr1 = [2, 4, 6];const arr2 = [3, 5, 7];console.log([...arr1, ...arr2]);
const arr1 = [2, 4, 6];const arr2 = [3, 5, 7];console.log([...arr1, ...arr2]);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7046 | 官方: 是 | 付费: 否

答案:

  • [x] [2, 4, 6, 3, 5, 7]
    [2, 4, 6, 3, 5, 7]
  • [ ] [2, 3, 4, 5, 6, 7]
    [2, 3, 4, 5, 6, 7]
  • [ ] [3,5,7,2,4,6]
    [3,5,7,2,4,6]
  • [ ] [3, 5, 7, 2, 4, 6]
    [3, 5, 7, 2, 4, 6]

854. Which method call is chained to handle a successful response returned by fetch()?

哪个方法调用被链接起来处理fetch()返回的成功响应?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7049 | 官方: 是 | 付费: 否

答案:

  • [ ] done()
    done()

    done()
  • [x] then()
    then()

    then()
  • [ ] finally()
    finally()

    finally()
  • [ ] catch()
    catch()

    catch()

855. Which choice is not an array method?

哪个选项不是数组方法?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e704c | 官方: 是 | 付费: 否

答案:

  • [ ] array.slice()
    array.slice()

    array.slice()
  • [ ] array.shift()
    array.shift()

    array.shift()
  • [ ] array.push()
    array.push()

    array.push()
  • [x] array.replace()
    array.replace()

    array.replace()

856. Which JavaScript loop ensures that at least a singular iteration will happen?

哪个JavaScript循环确保至少会执行一次迭代?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e704f | 官方: 是 | 付费: 否

答案:

  • [x] do…while
    do…while

    do…while
  • [ ] forEach
    forEach

    forEach
  • [ ] while
    while

    while
  • [ ] for
    for

    for

857. What will be logged to the console?

什么将被记录到控制台?
console.log(typeof 'blueberry');
console.log(typeof 'blueberry');
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7054 | 官方: 是 | 付费: 否

答案:

  • [x] string
    string

    string
  • [ ] array
    array

    array
  • [ ] Boolean
    Boolean

    布尔值
  • [ ] object
    object

    object

858. What is the output that is printed when the div containing the text "Click Here" is clicked?

当包含文本“Click Here”的 div 被点击时,打印出的输出是什么?
//HTML Markup
> 
//HTML标记
<div id="A">  <div id="B">    <div id="C">Click Here</div>  </div></div>
<div id="A"> <div id="B"> <div id="C">Click Here</div> </div></div>
//JavaScriptdocument.querySelectorAll('div').forEach((e) => {
> 
//JavaScriptdocument.querySelectorAll('div').forEach((e) => {
  e.onclick = (e) => console.log(e.currentTarget.id);});
e.onclick = (e) => console.log(e.currentTarget.id);});
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7057 | 官方: 是 | 付费: 否

答案:

  • [x] C B A
    C B A

    C B A
  • [ ] A
    A

    A
  • [ ] C
    C

    C
  • [ ] A B C
    A B C

    A B C

859. What will this code log to the console?

这段代码会在控制台记录什么?
const myNumbers = [1, 2, 3, 4, 5, 6, 7];const myFunction = (arr) => {
> 
const myNumbers = [1, 2, 3, 4, 5, 6, 7];const myFunction = (arr) => {
  return arr.map((x) => x + 3).filter((x) => x < 7);};console.log(myFunction(myNumbers));
return arr.map((x) => x + 3).filter((x) => x < 7);};console.log(myFunction(myNumbers));
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e705b | 官方: 是 | 付费: 否

答案:

  • [ ] [4,5,6,7,8,9,10]
    [4,5,6,7,8,9,10]
  • [ ] [4,5,6,7]
    [4,5,6,7]
  • [ ] [1,2,3,4,5,6]
    [1,2,3,4,5,6]
  • [x] [4,5,6]
    [4,5,6]

860. What does this code print to the console?

这段代码向控制台打印什么?
let rainForestAcres = 10;let animals = 0;while (rainForestAcres < 13 || animals <= 2) {
> 
let rainForestAcres = 10;let animals = 0;while (rainForestAcres < 13 || animals <= 2) {
  rainForestAcres++;  animals += 2;}
> rainForestAcres++;  animals += 2;}
console.log(animals);
console.log(animals);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e705e | 官方: 是 | 付费: 否

答案:

  • [ ] 2
    2
  • [ ] 4
    4
  • [x] 6
    6
  • [ ] 8
    8

861. Which snippet could you add to this code to print "YOU GOT THIS" to the console?

你可以在此代码中添加哪个片段,以便在控制台打印 "YOU GOT THIS"?
let cipherText = [...'YZOGUT QGMORTZ MTRHTILS'];let plainText = '';/* Missing Snippet */console.log(plainText); //Prints YOU GOT THIS
let cipherText = [...'YZOGUT QGMORTZ MTRHTILS'];let plainText = '';/* Missing Snippet */console.log(plainText); //Prints YOU GOT THIS
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7062 | 官方: 是 | 付费: 否

答案:

  • [ ] A
    for (let key of cipherText.keys()) {

    for (let key of cipherText.keys()) {
    plainText += key % 2 === 0 ? key : ' ';}
    plainText += key % 2 === 0 ? key : ' ';}

A

A
for (let key of cipherText.keys()) {
for (let key of cipherText.keys()) {
plainText += key % 2 === 0 ? key : ' ';}
plainText += key % 2 === 0 ? key : ' ';}
  • [ ] B
    for (let [index, value] of cipherText.entries()) {

    for (let [index, value] of cipherText.entries()) {
    plainText += index % 2 !== 0 ? value : '';}
    plainText += index % 2 !== 0 ? value : '';}

B

B
for (let [index, value] of cipherText.entries()) {
for (let [index, value] of cipherText.entries()) {
plainText += index % 2 !== 0 ? value : '';}
plainText += index % 2 !== 0 ? value : '';}
  • [x] C
    for (let [index, value] of cipherText.entries()) {

    for (let [index, value] of cipherText.entries()) {
    plainText += index % 2 === 0 ? value : '';}
    plainText += index % 2 === 0 ? value : '';}

C

C
for (let [index, value] of cipherText.entries()) {
for (let [index, value] of cipherText.entries()) {
plainText += index % 2 === 0 ? value : '';}
plainText += index % 2 === 0 ? value : '';}
  • [ ] D
    for (let value of cipherText) {

    for (let value of cipherText) {
    plainText += value;}
    plainText += value;}

D

D
for (let value of cipherText) {
for (let value of cipherText) {
plainText += value;}
plainText += value;}

862. Which Pokemon will be logged to the console?

哪个宝可梦会被记录到控制台?
var pokedex = ['Snorlax', 'Jigglypuff', 'Charmander', 'Squirtle'];pokedex.pop();console.log(pokedex.pop());
var pokedex = ['Snorlax', 'Jigglypuff', 'Charmander', 'Squirtle'];pokedex.pop();console.log(pokedex.pop());
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7065 | 官方: 是 | 付费: 否

答案:

  • [x] Charmander
    Charmander

    小火龙
  • [ ] Jigglypuff
    Jigglypuff

    胖丁
  • [ ] Snorlax
    Snorlax

    卡比兽
  • [ ] Squirtle
    Squirtle

    杰尼龟

863. Which statement can be used to select the element from the DOM containing the text "The LinkedIn Learning library has great JavaScript courses" from this markup?

从该标记中,哪条语句可用于选择包含文本“The LinkedIn Learning library has great JavaScript courses”的DOM元素?
<h1 class="content">LinkedIn Learning</h1><div class="content">  <span class="content">The LinkedIn Learning library has great JavaScript courses!</span></div>
<h1 class="content">LinkedIn Learning</h1><div class="content">  <span class="content">The LinkedIn Learning library has great JavaScript courses!</span></div>
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7068 | 官方: 是 | 付费: 否

答案:

  • [ ] document.querySelector("div.content")
    document.querySelector("div.content")

    document.querySelector("div.content")
  • [x] document.querySelector("span.content")
    document.querySelector("span.content")

    document.querySelector("span.content")
  • [ ] document.querySelector(".content")
    document.querySelector(".content")

    document.querySelector(".content")
  • [ ] document.querySelector("div.span")
    document.querySelector("div.span")

    document.querySelector("div.span")

864. Which value is not falsey?

哪个值不是假值?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e706b | 官方: 是 | 付费: 否

答案:

  • [x] []
    []
  • [ ] undefined
    undefined

    undefined
  • [ ] 0
    0
  • [ ] null
    null

    null

865. What line of code causes this code segment to throw an error?

哪行代码导致此代码段抛出错误?
const lion = 1;let tiger = 2;var bear;++lion;bear += lion + tiger;tiger++;
const lion = 1;let tiger = 2;var bear;++lion;bear += lion + tiger;tiger++;
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e706e | 官方: 是 | 付费: 否

答案:

  • [x] line 5, because lion cannot be reassigned a value
    line 5, because lion cannot be reassigned a value

    第5行,因为lion不能被重新赋值
  • [ ] line 6, because the += operator cannot be used with the undefined variable bear
    line 6, because the += operator cannot be used with the undefined variable bear

    第 6 行,因为 += 运算符不能用于未定义的变量 bear
  • [ ] line 5, because the prefix (++) operator does not exist in JavaScript
    line 5, because the prefix (++) operator does not exist in JavaScript

    第 5 行,因为前缀 (++) 运算符在 JavaScript 中不存在
  • [ ] line 3, because the variable bear is left undefined
    line 3, because the variable bear is left undefined

    第 3 行,因为变量 bear 被保留为未定义

866. What will be the value of result after running this code?

运行这段代码后,result 的值会是什么?
const person = { name: 'Dave', age: 40, hairColor: 'blue' };const result = Object.keys(person).map((x) => x.toUpperCase());
const person = { name: 'Dave', age: 40, hairColor: 'blue' };const result = Object.keys(person).map((x) => x.toUpperCase());
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7072 | 官方: 是 | 付费: 否

答案:

  • [ ] It will throw a TypeError.
    It will throw a TypeError.

    它会抛出一个 TypeError。
  • [ ] ["Name", "Age", "HairColor"]
    ["Name", "Age", "HairColor"]

    ["Name", "Age", "HairColor"]
  • [ ] ["DAVE", 40, "BLUE"]
    ["DAVE", 40, "BLUE"]

    ["DAVE", 40, "BLUE"]
  • [x] ["NAME", "AGE", "HAIRCOLOR"]
    ["NAME", "AGE", "HAIRCOLOR"]

    ["NAME", "AGE", "HAIRCOLOR"]

867. Which snippet could you insert to this code to print "swim" to the console?

哪个代码片段可以插入到此代码中以在控制台打印“swim”?
let animals = ["eagle", "osprey", "salmon"];let key = animal => animal === "salmon";if(/* Insert Snippet Here */){
> 
let animals = ["eagle", "osprey", "salmon"];let key = animal => animal === "salmon";if(/* Insert Snippet Here */){
  console.log("swim");}
console.log("swim");}
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7076 | 官方: 是 | 付费: 否

答案:

  • [ ] animals.every(key)
    animals.every(key)

    animals.every(key)
  • [ ] animals.some(key).length === 1
    animals.some(key).length === 1

    animals.some(key).length === 1
  • [ ] animals.filter(key) === true
    animals.filter(key) === true

    animals.filter(key) === true
  • [x] animals.some(key)
    animals.some(key)

    animals.some(key)

868. What is the output of this code?

这段代码的输出是什么?
class RainForest {
> 
class RainForest {
  static minimumRainFall = 60;}
> static minimumRainFall = 60;}
let congo = new RainForest();RainForest.minimumRainFall = 80;console.log(congo.minimumRainFall);
let congo = new RainForest();RainForest.minimumRainFall = 80;console.log(congo.minimumRainFall);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7079 | 官方: 是 | 付费: 否

答案:

  • [x] undefined
    undefined

    undefined
  • [ ] None of these answers, as static is not a feature in Javascript.
    None of these answers, as static is not a feature in Javascript.

    以上均不对,因为 static 不是 Javascript 的特性。
  • [ ] 60
    60
  • [ ] 80
    80

869. How can you attempt to access the property a.b on obj without throwing an error if a is undefined?

如何尝试访问 obj 上的属性 a.b,而不会在 a 为 undefined 时抛出错误?
let obj = {};
let obj = {};
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e707c | 官方: 是 | 付费: 否

答案:

  • [ ] obj?.a.b
    obj?.a.b

    obj?.a.b
  • [x] obj.a?.b
    obj.a?.b

    obj.a?.b
  • [ ] obja
    obja

    obja
  • [ ] obj.?a.?b
    obj.?a.?b

    obj.?a.?b

870. What happens when you run this code?

运行这段代码会发生什么?
if (true) {
> 
if (true) {
  var x = 5;  const y = 6;  let z = 7;}
> var x = 5;  const y = 6;  let z = 7;}
console.log(x + y + z);
console.log(x + y + z);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e707f | 官方: 是 | 付费: 否

答案:

  • [ ] It will throw a ReferenceError about x.
    It will throw a ReferenceError about x.

    它将抛出一个关于x的ReferenceError。
  • [ ] It will print 18.
    It will print 18.

    它将打印18。
  • [ ] It will print undefined.
    It will print undefined.

    它将打印undefined。
  • [x] It will throw a ReferenceError about y.
    It will throw a ReferenceError about y.

    它将抛出一个关于y的ReferenceError。

871. What does this code print to the console?

这段代码向控制台打印什么?
const x = [1, 2];const y = [5, 7];const z = [...x, ...y];console.log(z);
const x = [1, 2];const y = [5, 7];const z = [...x, ...y];console.log(z);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7083 | 官方: 是 | 付费: 否

答案:

  • [x] [1,2,5,7]
    [1,2,5,7]
  • [ ] [[1, 2], [5, 7]]
    [[1, 2], [5, 7]]
  • [ ] [2,7]
    [2,7]
  • [ ] [2,1,7,5]
    [2,1,7,5]

872. Given this code, which statement will be evaluated as false?

鉴于这段代码,哪个语句会被判定为false?
const a = { x: 1 };const b = { x: 1 };
const a = { x: 1 };const b = { x: 1 };
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7086 | 官方: 是 | 付费: 否

答案:

  • [ ] a['x'] === b['x']
    a['x'] === b['x']

    a['x'] === b['x']
  • [ ] a != b
    a != b

    a != b
  • [x] a === b
    a === b

    a === b
  • [ ] a.x === b.x
    a.x === b.x

    a.x === b.x

873. What will this code log to the console?

这段代码会在控制台记录什么?
console.log(typeof 41.1);
console.log(typeof 41.1);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e708b | 官方: 是 | 付费: 否

答案:

  • [ ] Nothing. It resuults in a ReferenceError.
    Nothing. It resuults in a ReferenceError.

    什么也不打印。它导致了一个ReferenceError。
  • [ ] decimal
    decimal

    decimal
  • [ ] float
    float

    float
  • [x] number
    number

    number

874. What is the output of this code?

这段代码的输出是什么?
let scores = [];scores.push(1, 2);scores.pop();scores.push(3, 4);scores.pop();score = scores.reduce((a, b) => a + b);console.log(score);
let scores = [];scores.push(1, 2);scores.pop();scores.push(3, 4);scores.pop();score = scores.reduce((a, b) => a + b);console.log(score);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e708e | 官方: 是 | 付费: 否

答案:

  • [ ] 3
    3
  • [x] 4
    4
  • [ ] 6
    6
  • [ ] 7
    7

875. What does this code print to the console?

这段代码向控制台打印什么?
let bear = {
> 
let bear = {
  sound: 'roar',  roar() {
> sound: 'roar',  roar() {
    console.log(this.sound);  },};bear.sound = 'grunt';let bearSound = bear.roar;bearSound();
console.log(this.sound); },};bear.sound = 'grunt';let bearSound = bear.roar;bearSound();
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7093 | 官方: 是 | 付费: 否

答案:

  • [ ] Nothing is printed to the console.
    Nothing is printed to the console.

    控制台没有打印任何内容。
  • [ ] grunt
    grunt

    grunt
  • [x] undefined
    undefined

    undefined
  • [ ] roar
    roar

    roar

876. What is the output of this code?

这段代码的输出是什么?
var cat = { name: 'Athena' };function swap(feline) {
> 
var cat = { name: 'Athena' };function swap(feline) {
  feline.name = 'Wild';  feline = { name: 'Tabby' };}
> feline.name = 'Wild';  feline = { name: 'Tabby' };}
swap(cat);console.log(cat.name);
swap(cat);console.log(cat.name);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7096 | 官方: 是 | 付费: 否

答案:

  • [ ] undefined
    undefined

    undefined
  • [x] Wild
    Wild

    Wild
  • [ ] Tabby
    Tabby

    虎斑猫
  • [ ] Athena
    Athena

    雅典娜

877. What will this code output to the log?

这段代码会向日志输出什么?
var thing;let func = (str = 'no arg') => {
> 
var thing;let func = (str = 'no arg') => {
  console.log(str);};func(thing);func(null);
console.log(str);};func(thing);func(null);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e7099 | 官方: 是 | 付费: 否

答案:

  • [ ] null no arg
    null no arg

    null no arg
  • [ ] no arg no arg
    no arg no arg

    no arg no arg
  • [ ] null null
    null null

    null null
  • [x] no arg null
    no arg null

    no arg null

878. What will this code print to the console?

这段代码会在控制台打印什么?
const myFunc = () => {
> 
const myFunc = () => {
  const a = 2;  return () => console.log('a is ' + a);};const a = 1;const test = myFunc();test();
const a = 2; return () => console.log('a is ' + a);};const a = 1;const test = myFunc();test();
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e709c | 官方: 是 | 付费: 否

答案:

  • [ ] a is 1
    a is 1

    a is 1
  • [ ] a is undefined
    a is undefined

    a is undefined
  • [ ] It won't print anything.
    It won't print anything.

    它不会打印任何内容。
  • [x] a is 2
    a is 2

    a 是 2

879. What will this code print to the console?

这段代码会在控制台打印什么?
const myFunc = (num1, num2 = 2, num3 = 2) => {
> 
const myFunc = (num1, num2 = 2, num3 = 2) => {
  return num1 + num2 + num3;};let values = [1, 5];const test = myFunc(2, ...values);console.log(test);
return num1 + num2 + num3;};let values = [1, 5];const test = myFunc(2, ...values);console.log(test);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70a0 | 官方: 是 | 付费: 否

答案:

  • [x] 8
    8
  • [ ] 6
    6
  • [ ] 2
    2
  • [ ] 12
    12

880. Which code would you use to access the Irish flag?

你会用哪段代码来访问爱尔兰国旗?
var flagsJSON =  '{ "countries" : [' +  '{ "country":"Ireland" , "flag":"🇮🇪" },' +  '{ "country":"Serbia" , "flag":"🇷🇸" },' +  '{ "country":"Peru" , "flag":"🇵🇪" } ]}';var flagDatabase = JSON.parse(flagsJSON);
var flagsJSON =  '{ "countries" : [' +  '{ "country":"Ireland" , "flag":"🇮🇪" },' +  '{ "country":"Serbia" , "flag":"🇷🇸" },' +  '{ "country":"Peru" , "flag":"🇵🇪" } ]}';var flagDatabase = JSON.parse(flagsJSON);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70a3 | 官方: 是 | 付费: 否

答案:

  • [ ] flagDatabase.countries[1].flag
    flagDatabase.countries[1].flag

    flagDatabase.countries[1].flag
  • [x] flagDatabase.countries[0].flag
    flagDatabase.countries[0].flag

    flagDatabase.countries[0].flag
  • [ ] flagDatabase[1].flag
    flagDatabase[1].flag

    flagDatabase[1].flag
  • [ ] flagsJSON.countries[0].flag
    flagsJSON.countries[0].flag

    flagsJSON.countries[0].flag

881. Which snippet allows the acresOfRainForest variable to increase?

哪个代码片段能让 acresOfRainForest 变量增加?
let conservation = true;let deforestation = false;let acresOfRainForest = 100;if (/* Snipped goes here */){
> 
let conservation = true;let deforestation = false;let acresOfRainForest = 100;if (/* 此处填入片段 */){
    ++acresOfRainForest;}
++acresOfRainForest;}
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70a7 | 官方: 是 | 付费: 否

答案:

  • [x] conservation && !deforestation
    conservation && !deforestation

    conservation && !deforestation
  • [ ] !deforestation && !conservation
    !deforestation && !conservation

    !deforestation && !conservation
  • [ ] !conservation || deforestation
    !conservation || deforestation

    !conservation || deforestation
  • [ ] deforestation && conservation || deforestation
    deforestation && conservation || deforestation

    deforestation && conservation || deforestation

882. Which of these evaluate to true?

以下哪些结果为真?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70ab | 官方: 是 | 付费: 否

答案:

  • [x] Boolean("false")
    Boolean("false")

    Boolean("false")
  • [ ] Boolean("")
    Boolean("")

    Boolean("")
  • [ ] Boolean(0)
    Boolean(0)

    Boolean(0)
  • [ ] Boolean(NaN)
    Boolean(NaN)

    Boolean(NaN)

883. How would you add a data item named animal with a value of sloth to local storage for the current domain?

如何为当前域名向本地存储中添加一个名为 animal、值为 sloth 的数据项?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70ae | 官方: 是 | 付费: 否

答案:

  • [ ] LocalStorage.setItem("animal","sloth");
    LocalStorage.setItem("animal","sloth");

    LocalStorage.setItem("animal","sloth");
  • [ ] document.localStorage.setItem("animal","sloth");
    document.localStorage.setItem("animal","sloth");

    document.localStorage.setItem("animal","sloth");
  • [ ] localStorage.setItem({animal:"sloth"});
    localStorage.setItem({animal:"sloth"});

    localStorage.setItem({animal:"sloth"});
  • [x] localStorage.setItem("animal","sloth");
    localStorage.setItem("animal","sloth");

    localStorage.setItem("animal","sloth");

884. What value is printed to the console after this code execute?

这段代码执行后,控制台会输出什么值?
let cat = Object.create({ type: 'lion' });cat.size = 'large';let copyCat = { ...cat };cat.type = 'tiger';console.log(copyCat.type, copyCat.size);
let cat = Object.create({ type: 'lion' });cat.size = 'large';let copyCat = { ...cat };cat.type = 'tiger';console.log(copyCat.type, copyCat.size);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70b1 | 官方: 是 | 付费: 否

答案:

  • [ ] tiger large
    tiger large

    tiger large
  • [ ] lion undefined
    lion undefined

    lion undefined
  • [x] undefined large
    undefined large

    未定义的大型
  • [ ] lion large
    lion large

    狮子大

885. What does this code print to the console?

这段代码向控制台打印什么?
let animals = [{ type: 'lion' }, 'tiger'];let clones = animals.slice();clones[0].type = 'bear';clones[1] = 'sheep';console.log(animals[0].type, clones[0].type);console.log(animals[1], clones[1]);
let animals = [{ type: 'lion' }, 'tiger'];let clones = animals.slice();clones[0].type = 'bear';clones[1] = 'sheep';console.log(animals[0].type, clones[0].type);console.log(animals[1], clones[1]);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70b7 | 官方: 是 | 付费: 否

答案:

  • [x] bear bear
    tiger sheep

    虎羊
    bear bear
    熊熊
    tiger sheep
    虎羊
  • [ ] lion bear
    sheep sheep

    羊羊
    lion bear
    狮熊
    sheep sheep
    羊羊
  • [ ] bear bear
    tiger tiger

    虎虎
    bear bear
    熊熊
    tiger tiger
    虎虎
  • [ ] lion bear
    tiger sheep

    虎羊
    lion bear
    狮熊
    tiger sheep
    虎羊

886. What will be the output of the following code?

以下代码的输出将是什么?
a=5;b=4;alert(a++(+(+(+b))));
a=5;b=4;alert(a++(+(+(+b))));
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70ba | 官方: 是 | 付费: 否

答案:

  • [ ] 18
    18
  • [ ] 10
    10
  • [x] 9
    9
  • [ ] 20
    20

887. Which snippet could you add to this code to print "{"type": "tiger"}" to the console?

你可以在这段代码中添加哪个代码片段,以在控制台打印 "{“type”: "tiger"}"?
let cat = { type: "tiger", size: "large" };let json = /* Snippet here */;console.log(json); // print {"type":"tiger"}
let cat = { type: "tiger", size: "large" };let json = /* 此处为代码片段 */;console.log(json); // 打印 {"type":"tiger"}
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70bf | 官方: 是 | 付费: 否

答案:

  • [ ] cat.toJSON("type");
    cat.toJSON("type");

    cat.toJSON("type");
  • [x] JSON.stringify(cat, ["type"]);
    JSON.stringify(cat, ["type"]);

    JSON.stringify(cat, ["type"]);
  • [ ] JSON.stringify(cat);
    JSON.stringify(cat);

    JSON.stringify(cat);
  • [ ] JSON.stringify(cat, /type/);
    JSON.stringify(cat, /type/);

    JSON.stringify(cat, /type/);

888. Which document method is not used to get a reference to a DOM node?

哪个文档方法不用于获取 DOM 节点的引用?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70c2 | 官方: 是 | 付费: 否

答案:

  • [x] document.getNode();
    document.getNode();

    document.getNode();
  • [ ] document.getElementsByClassName();
    document.getElementsByClassName();

    document.getElementsByClassName();
  • [ ] document.querySelectorAll();
    document.querySelectorAll();

    document.querySelectorAll();
  • [ ] document.querySelector();
    document.querySelector();

    document.querySelector();

889. In JavaScript, all objects inherit a built-in property from a ___.

在 JavaScript 中,所有对象都继承自 ___ 的一个内置属性。
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70c5 | 官方: 是 | 付费: 否

答案:

  • [ ] node
    node

    节点
  • [ ] instance variable
    instance variable

    实例变量
  • [x] prototype
    prototype

    原型
  • [ ] accessor
    accessor

    访问器

890. Which of the following are not server-side Javascript objects?

以下哪些不是服务器端 JavaScript 对象?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70c8 | 官方: 是 | 付费: 否

答案:

  • [ ] Date
    Date

    Date
  • [x] FileUpload
    FileUpload

    FileUpload
  • [ ] Function
    Function

    函数
  • [ ] All of the above
    All of the above

    以上所有

891. What will be the output of the following code snippet?

以下代码片段的输出是什么?
const obj1 = { first: 20, second: 30, first: 50 };console.log(obj1);
const obj1 = { first: 20, second: 30, first: 50 };console.log(obj1);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70cb | 官方: 是 | 付费: 否

答案:

  • [ ] first: 30 , second: 50
    first: 30 , second: 50

    first: 30 , second: 50
  • [x] first: 50 , second: 30
    first: 50 , second: 30

    first: 50 , second: 30
  • [ ] first: 30 , second: 20
    first: 30 , second: 20

    first: 30 , second: 20
  • [ ] None of the above
    None of the above

    以上都不是

892. Which object in Javascript doesn't have a prototype?

Javascript 中哪个对象没有原型?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70ce | 官方: 是 | 付费: 否

答案:

  • [x] Base Object
    Base Object

    基对象
  • [ ] All objects have prototype
    All objects have prototype

    所有对象都有原型
  • [ ] None of the objects have prototype
    None of the objects have prototype

    所有对象都没有原型
  • [ ] None of the above
    None of the above

    以上都不是

893. What does … operator do in JS?

在 JS 中…运算符的作用是什么?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70d1 | 官方: 是 | 付费: 否

答案:

  • [x] Used to spread iterables to individual elements
    Used to spread iterables to individual elements

    用于将可迭代对象展开为单个元素
  • [ ] Describe datatype of undefined
    Describe datatype of undefined

    描述 undefined 的数据类型
  • [ ] No such operator exists
    No such operator exists

    不存在这样的运算符
  • [ ] None of the above
    None of the above

    以上都不是

894. How to stop an interval timer in Javascript?

如何停止 JavaScript 中的间隔定时器?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70d4 | 官方: 是 | 付费: 否

答案:

  • [x] clearInterval
    clearInterval

    clearInterval
  • [ ] clearTimer
    clearTimer

    clearTimer
  • [ ] intervalOver
    intervalOver

    intervalOver
  • [ ] None of the above
    None of the above

    以上都不是

895. What will be the output of the following code snippet?

以下代码片段的输出是什么?
print(typeof NaN);
print(typeof NaN);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70d8 | 官方: 是 | 付费: 否

答案:

  • [ ] Object
    Object

    对象
  • [x] Number
    Number

    数字
  • [ ] String
    String

    字符串
  • [ ] None of the above
    None of the above

    以上都不是

896. What will be the output of the following code snippet?

以下代码片段的输出是什么?
<script type="text/javascript">a = 5 + "9"; document.write(a);</script>
<script type="text/javascript">a = 5 + "9"; document.write(a);</script>
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70dd | 官方: 是 | 付费: 否

答案:

  • [ ] Compilation Error
    Compilation Error

    编译错误
  • [ ] 14
    14
  • [ ] Runtime Error
    Runtime Error

    运行时错误
  • [x] 59
    59

897. Which of the following methods can be used to display data in some form using Javascript?

以下哪些方法可用于使用 Javascript 以某种形式显示数据?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70e0 | 官方: 是 | 付费: 否

答案:

  • [ ] document.write()
    document.write()

    document.write()
  • [ ] console.log()
    console.log()

    console.log()
  • [ ] window.alert()
    window.alert()

    window.alert()
  • [x] all of the above
    all of the above

    以上所有选项

898. What value is assigned to total after this code executes?

此代码执行后,total 被赋了什么值?
function sum(num1, num2 = 2, num3 = 3) {
> 
function sum(num1, num2 = 2, num3 = 3) {
  return num1 + num2 + num3;}
> return num1 + num2 + num3;}
let values = [1, 5];let total = sum(4, ...values);
let values = [1, 5];let total = sum(4, ...values);
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70e3 | 官方: 是 | 付费: 否

答案:

  • [x] 10
    10
  • [ ] 6
    6
  • [ ] 7
    7
  • [ ] 8
    8

899. Which statement is applicable to the defer attribute of the HTML

以下哪个语句适用于 HTML 的 defer 属性?
  • 知识点: 前端 (主题: javascript, web-development;标签: JavaScript)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 698163d8461d5a4fad0e70e6 | 官方: 是 | 付费: 否

答案:

  • [x] None of the above
    None of the above

    以上都不是
  • [ ] All of the above
    All of the above

    以上所有
  • [ ] It depends on the runtime
    It depends on the runtime

    这取决于运行时环境
  • [ ] This is not possible
    This is not possible

    这是不可能的

900. Google 前端面试(Frontend Interview)通常会考哪些方向?

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69896ec069b2be043c3e7a62 | 官方: 是 | 付费: 否

答案:

Google 前端面试一般会同时考察计算机科学基础(Computer Science Fundamentals)与前端工程能力(Frontend Engineering Capability)。常见覆盖点包括:前端延迟/性能(Frontend Latency/Performance)、用地道 JavaScript 实现标准算法(Standard Algorithm)、JavaScript 的优势与短板、Web 安全(Web Security)(XSS(Cross-Site Scripting)/CSRF(Cross-Site Request Forgery))、原型继承(Prototypal Inheritance)、DOM API(Document Object Model API)与操作、CSS 操作、浏览器/DOM 事件(DOM Event)与处理、XHR(XMLHttpRequest)/Fetch 与 HTTP Header(HTTP Header)、闭包(Closure)等。

901. 对 HTML 节点做 DFS(Depth-First Search,深度优先遍历)。

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69896ec069b2be043c3e7a89 | 官方: 是 | 付费: 否

答案:

可用递归(Recursion)或显式栈(Explicit Stack)实现:从根节点开始,先处理当前节点,再遍历其子节点(前序(Preorder));或先遍历子节点再处理(后序(Postorder))。注意 DOM(Document Object Model)遍历用 element.children(仅元素节点)或 childNodes(含文本/注释)。

902. 给定一个 timeline(时间线),写 JavaScript 选择 timeline 选区内的所有节点。

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69896ec069b2be043c3e7ab0 | 官方: 是 | 付费: 否

答案:

通用思路:把“timeline 选区”映射为可判定的区间(如时间戳范围、像素范围、index 范围),然后遍历候选节点集合,对每个节点取其起止时间/位置,做区间相交判断(Interval Intersection)(nodeEnd >= selStart && nodeStart <= selEnd),命中则加入结果;若节点很多可用排序 + 双指针(Two Pointers)/二分(Binary Search)减少遍历成本。

903. 解释 CSS Box Model(盒模型)。

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69896ec069b2be043c3e7ae9 | 官方: 是 | 付费: 否

答案:

盒模型(Box Model)描述元素占据空间的组成:content(内容)+ padding(内边距)+ border(边框)+ margin(外边距)。默认 box-sizing: content-box 时,声明的 width/height 仅包含 content;border-box 则把 padding/border 也计入 width/height。布局与溢出问题常与盒模型计算有关。

904. 在浏览器地址栏输入 URL(Uniform Resource Locator)并回车后,会发生什么?

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 69896ec069b2be043c3e7af5 | 官方: 是 | 付费: 否

答案:

典型流程:URL 解析与规范化 → DNS(Domain Name System)解析 → 建立连接(TCP(Transmission Control Protocol)+TLS(Transport Layer Security)/QUIC(Quick UDP Internet Connections))→ 发送 HTTP(HyperText Transfer Protocol)请求 → 服务端响应(HTML(HyperText Markup Language))→ 解析 HTML 构建 DOM(Document Object Model),同时下载解析 CSS(Cascading Style Sheets)构建 CSSOM(CSS Object Model)→ 合成 Render Tree(渲染树)→ layout(回流(Reflow))→ paint(绘制)→ 合成(Compositing)。过程中还会触发 JS(JavaScript)执行、资源加载、缓存命中与重验证等。

905. Amazon 前端面试通常更看重什么?

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406c68 | 官方: 是 | 付费: 否

答案:

Amazon 很强调行为面(Behavioral Interview)与Leadership Principles(领导力准则),因此除了技术能力,也要准备大量 STAR(Situation, Task, Action, Result)案例来回答行为题。同时,前端岗位仍会考察前端基础与编码能力(Coding Ability)(JS/CSS/DOM/UI 实现、系统设计(System Design)、以及一定的算法/CS 基础)。

906. 什么是 CSS box model(盒模型)?

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406c70 | 官方: 是 | 付费: 否

答案:

盒模型(Box Model)描述元素占据空间的组成:content(内容)+ padding(内边距)+ border(边框)+ margin(外边距)。默认 box-sizing: content-box 时,width/height 只包含内容区;设置 box-sizing: border-box 则把 padding/border 也计入 width/height,更符合 UI(User Interface)设计对“块尺寸”的直觉。

907. 什么是 JavaScript closure(闭包)?

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406c75 | 官方: 是 | 付费: 否

答案:

闭包(Closure)是函数与其词法作用域(Lexical Scope)的组合:当一个内部函数引用了外部函数的变量,即使外部函数执行完毕,这些变量也会因被引用而保留。常用于封装私有状态、函数工厂(Function Factory)、回调(Callback)中保留上下文,以及实现 debounce(防抖)/throttle(节流)等。

908. 在浏览器地址栏输入 URL(Uniform Resource Locator)并回车后,会发生什么?

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406c7a | 官方: 是 | 付费: 否

答案:

典型流程:URL 解析与规范化 → DNS(域名系统) 解析 → 建立连接(TCP(传输控制协议)+TLS(传输层安全协议) 或 QUIC(快速 UDP 互联网连接))→ 发送 HTTP(超文本传输协议) 请求 → 接收响应(HTML(超文本标记语言)/资源)→ 解析 HTML 构建 DOM(文档对象模型)、解析 CSS(层叠样式表) 构建 CSSOM(CSS 对象模型) → 合成渲染树(Render Tree) → layout(回流)→ paint(绘制)→ compositing(合成)。过程中还涉及缓存命中/重验证、脚本执行、资源加载与优先级等。

909. 实现 getElementsByStyle(property, value):返回 DOM 中所有样式匹配的元素(例如 color 为 #fff)。

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406c86 | 官方: 是 | 付费: 否

答案:

常见做法:遍历 DOM 元素(如 document.querySelectorAll('*') 或树遍历),对每个元素取 getComputedStyle(el)[property] 与目标 value 比较。注意:颜色可能被标准化为 rgb/rgba 字符串,因此可能需要把输入(#fff)与 computed 值做同一化(例如转为 rgb)。性能上,尽量缩小遍历范围或使用更具体的选择器(如果可行)。

910. 用数组对象实现一个数据表格(HTML/CSS/JS),支持搜索与排序。

  • 知识点: 前端 / 算法与数据结构
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406c8e | 官方: 是 | 付费: 否

答案:

要点:表头渲染(从字段列表生成)、数据行渲染、搜索(输入框 + 过滤逻辑,建议防抖)、排序(点击表头切换升/降序,稳定排序更佳)、状态管理(当前 query(查询)、sortKey(排序键)、sortDir(排序方向)、分页可选)。大数据量可做分页或虚拟滚动(Virtual Scrolling);无障碍可加 aria-sort 与键盘操作。

911. 实现一个搜索栏(HTML/CSS/JS)。

  • 知识点: 前端
  • 类型: technical | 难度: medium | 子类型:
  • 分类: fullstack
  • id: 6989709a69b2be043c406ca1 | 官方: 是 | 付费: 否

答案:

基础版本:输入框 + 提交按钮,监听 input/submit 事件并触发查询。增强:自动补全(debounce)、高亮匹配、键盘导航、清除按钮、加载与错误提示。无障碍(Accessibility):label/aria-label、role=search、可见焦点样式。

912. Is having a project on Web or Android Development or Machine Learning a must for being hired at Amazon?

在亚马逊被录用是否必须拥有Web或Android开发或机器学习的项目?
  • 知识点: 前端 / 数据工程与数据科学/AI (标签: interviewbit, amazon, company-specific)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: general
  • 公司: 亚马逊
  • id: 69b3792b58d557c902b982ae | 官方: 否 | 付费: 否

答案:

No, only good problem-solving skills are required to get hired at Amazon for an SDE position. Having said that, you will always get brownie points if you have a good project or two in your Resume as it shows that you are referenced and interested in the domain on which you have made your project.

不,要在亚马逊获得SDE职位,只需要良好的问题解决能力。话虽如此,如果您的简历中有一两个好的项目,您总是会获得加分,因为这表明您对所制作项目的领域有所参考和兴趣。

Coding Problems

0/4

Easy Problems

简单问题

Greedy Algorithm

贪心算法

Dynamic Programming

动态规划

Majority Element

多数元素

Easy

简单

19.7 Mins

19.7分钟

Solve

解答

Unique Binary Search Trees

唯一二叉搜索树

Easy

简单

62.1 Mins

62.1 分钟

Solve

解答

Best Time to Buy and Sell Stocks II

买卖股票的最佳时机 II

Easy

简单

40.18 Mins

40.18分钟

Solve

解答

Best Time to Buy and Sell Stocks I

买卖股票的最佳时机 I

Easy

简单

28.13 Mins

28.13分钟

Solve

解答

0/5

Intermediate Problems

中级问题

Greedy Algorithm

贪心算法

Dynamic Programming

动态规划

Gas Station

加油站

Medium

中等

56.42 Mins

56.42分钟

Solve

解答

Distribute Candy

分发糖果

Medium

中等

65.48 Mins

65.48分钟

Solve

解答

Longest Increasing Subsequence

最长递增子序列

Medium

中等

30.39 Mins

30.39分钟

Solve

解答

Max Product Subarray

最大乘积子数组

Medium

中等

65.25 Mins

65.25 分钟

Solve

解答

Ways to Decode

解码方法

Medium

中等

70.8 Mins

70.8分钟

Solve

解答

0/1

Advanced Problems

进阶问题

Dynamic Programming

动态规划

Best Time to Buy and Sell Stocks III

买卖股票的最佳时机 III

Hard

困难

64.56 Mins

64.56 分钟

Solve

解答

913. How do you choose an element from a component template?

如何从组件模板中选择一个元素?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98648 | 官方: 否 | 付费: 否

答案:

To directly access items in the view, use the @ViewChild directive. Consider an input item with a reference.

要直接访问视图中的项目,请使用 @ViewChild 指令。考虑一个带有引用的输入项目。

and construct a view child directive that is accessed in the ngAfterViewInit lifecycle hook

并构造一个在 ngAfterViewInit 生命周期钩子中访问的视图子指令

@ViewChild('example') input;

@ViewChild('example') input;

ngAfterViewInit() {

ngAfterViewInit() {
console.log(this.input.nativeElement.value);
console.log(this.input.nativeElement.value);
}

914. How does one share data between components in Angular?

在Angular中如何在组件之间共享数据?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9864b | 官方: 否 | 付费: 否

答案:

Following are the commonly used methods by which one can pass data between components in angular:

以下是Angular中常用的在组件之间传递数据的方法:
  • Parent to child using @Input decorator

Consider the following parent component:

考虑以下父组件:
@Component({
@Component({
selector: 'app-parent',
选择器: 'app-parent',
template: `
template: `


` ,
styleUrls: ['./parent.component.css']
样式URL: ['./parent.component.css']
})
export class ParentComponent{
export class ParentComponent{
data:string = "Message from parent";
data:string = "Message from parent";
constructor()
constructor()
}
In the above parent component, we are passing “data” property to the following child component:
在上述父组件中,我们将“data”属性传递给以下子组件:

import { Component, Input} from '@angular/core';

import { Component, Input} from '@angular/core';
@Component({
@Component({
selector: 'app-child',
selector: 'app-child',
template:`
template:`

{{data}}

{{data}}

`,
styleUrls: ['./child.component.css']
styleUrls: ['./child.component.css']
})
export class ChildComponent {
export class ChildComponent {
@Input() data:string
@Input() data:string
constructor()
constructor()
}
In the child component, we are using @Input decorator to capture data coming from a parent component and using it inside the child component’s template.
在子组件中,我们使用 @Input 装饰器来捕获来自父组件的数据,并在子组件的模板中使用它。

  • Child to parent using @ViewChild decorator

Child component:

子组件:
import {Component} from '@angular/core';
import {Component} from '@angular/core';
@Component({
@Component({
selector: 'app-child',
selector: 'app-child',
template:`
template:`

{{data}}

{{data}}

`,
styleUrls: ['./child.component.css']
styleUrls: ['./child.component.css']
})
export class ChildComponent {
export class ChildComponent {
data:string = "Message from child to parent";
data:string = "Message from child to parent";
constructor()
constructor()
}
Parent Component
父组件

import { Component,ViewChild, AfterViewInit} from '@angular/core';

从'@angular/core'中导入 { Component, ViewChild, AfterViewInit };
import { ChildComponent } from './../child/child.component';
从'./../child/child.component'中导入 { ChildComponent };
@Component({
@Component({
selector: 'app-parent',
选择器: 'app-parent',
template: `
template: `

{{dataFromChild}}

{{dataFromChild}}

` ,
styleUrls: ['./parent.component.css']
样式URL: ['./parent.component.css']
})
export class ParentComponent implements AfterViewInit {
导出类 ParentComponent 实现 AfterViewInit {
dataFromChild: string;
dataFromChild: 字符串;
@ViewChild(ChildComponent,{static:false}) child;
@ViewChild(ChildComponent, {static: false}) child;
ngAfterViewInit(){
ngAfterViewInit(){
this.dataFromChild = this.child.data;
this.dataFromChild = this.child.data;
}
constructor()
constructor()
}
In the above example, a property named “data” is passed from the child component to the parent component.
在上述示例中,一个名为“data”的属性从子组件传递到父组件。

@ViewChild decorator is used to reference the child component as “child” property.

@ViewChild装饰器用于将子组件引用为“child”属性。

Using the ngAfterViewInit hook, we assign the child’s data property to the messageFromChild property and use it in the parent component’s template. - Child to parent using @Output and EventEmitter

使用 ngAfterViewInit 钩子,我们将子组件的 data 属性赋值给 messageFromChild 属性,并在父组件的模板中使用它。- 使用 @Output 和 EventEmitter 从子组件向父组件传递数据
In this method, we bind a DOM element inside the child component, to an event ( click event for example ) and using this event we emit data that will captured by the parent component:
在此方法中,我们将子组件内的 DOM 元素绑定到一个事件(例如点击事件),并利用此事件发出将由父组件捕获的数据:

Child Component:

子组件:

import {Component, Output, EventEmitter} from '@angular/core';

import {Component, Output, EventEmitter} from '@angular/core';
@Component({
@Component({
selector: 'app-child',
selector: 'app-child',
template:`
template:`


`,
styleUrls: ['./child.component.css']
styleUrls: ['./child.component.css']
})
export class ChildComponent {
export class ChildComponent {
data:string = "Message from child to parent";
data:string = "Message from child to parent";
@Output() dataEvent = new EventEmitter();
@Output() dataEvent = new EventEmitter();
constructor()
constructor()
emitData(){
emitData(){
this.dataEvent.emit(this.data);
this.dataEvent.emit(this.data);
}
}
As you can see in the child component, we have used @Output property to bind an EventEmitter . This event emitter emits data when the button in the template is clicked.
正如你在子组件中所见,我们使用了 @Output 属性来绑定一个 EventEmitter。当模板中的按钮被点击时,该事件发射器会发出数据。

In the parent component’s template we can capture the emitted data like this:

在父组件的模板中,我们可以这样捕获发出的事件数据:


Then inside the receiveData function we can handle the emitted data:
然后在 receiveData 函数内部,我们可以处理发出的事件数据:

receiveData($event){

receiveData($event){
this.dataFromChild = $event;
this.dataFromChild = $event;
}

915. How do you deal with errors in observables?

你如何处理 observables 中的错误?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9864e | 官方: 否 | 付费: 否

答案:

Instead of depending on try/catch, which is useless in an asynchronous context, you may manage problems by setting an error callback on the observer.

与其依赖在异步上下文中无用的 try/catch,你可以通过为观察者设置错误回调来管理问题。

Example: You may create an error callback as shown below.

示例:你可以像下面这样创建一个错误回调。

myObservable.subscribe({

myObservable.subscribe({
next(number) { console.log('Next number: ' + number)},
next(number) { console.log('Next number: ' + number)},
error(err) { console.log('An error received ' + err)}
error(err) { console.log('An error received ' + err)}
});

916. How can I include SASS into an Angular project?

我如何将 SASS 集成到 Angular 项目中?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98651 | 官方: 否 | 付费: 否

答案:

You may use the ng new command while building your project using angular CLI. All of your components are generated using preset sass files.

你可以使用 angular CLI 构建项目时通过 ng new 命令来实现。你的所有组件都会使用预设的 sass 文件生成。

ng new --style = sass

ng new --style = sass
If you want to change the style of your project, use the ng set command.
如果你想更改项目的样式,请使用 ng set 命令。

ng set defaults.styleExt scss

ng set defaults.styleExt scss

917. What happens when you use the script tag within a template?

当您在模板中使用script标签时会发生什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98654 | 官方: 否 | 付费: 否

答案:

Angular detects the value as unsafe and sanitizes it automatically, removing the script tag but retaining safe material such as the script tag's text content. This reduces the potential of script injection attacks. If you continue to use it, it will be disregarded, and a warning will display in the browser console.

Angular会将该值检测为不安全的并自动进行清理,移除script标签,但保留安全的内容,例如script标签的文本内容。这降低了脚本注入攻击的可能性。如果您继续使用它,它会被忽略,并且浏览器控制台中会显示警告。

Example: Consider the case of innerHtml property binding, which results in an XSS vulnerability.

示例:考虑innerHtml属性绑定的情况,这会导致XSS漏洞。

export class InnerHtmlBindingComponent {

导出类InnerHtmlBindingComponent {
// For example, a attacker-controlled value from a URL using malicious scripts.
// 例如,攻击者控制的值来自使用恶意脚本的URL。
htmlSnippet = 'Template Syntax';
htmlSnippet = '模板 语法';
}
Conclusion
结论
For new applicants for the role of Angular developer, theoretical and fundamental ideas are required, but for an experienced individual, both applied and practical concepts are essential. Many of the Angular interview questions for experienced candidates will be about your prior project. This article contains a collection of frequently asked job interview questions that apply to all of Angular's modules. An applicant who hopes to land a position as an Angular developer should review these questions once again before arriving at their interview.
对于申请Angular开发人员角色的新求职者,理论和基础概念是必需的,但对于有经验的人员,应用和实践概念至关重要。许多针对有经验候选人的Angular面试问题将涉及您之前的项目。本文包含了一系列常见的求职面试问题,适用于Angular的所有模块。希望在Angular开发人员职位上获得一席之地的申请者应在面试前再次复习这些问题。

Additional Interview Resources

其他面试资源
  • Angular 8 Interview Questions
  • Angularjs Interview Questions
  • Full Stack Developer Interview Questions
  • TypeScript Interview Questions
  • React Interview Questions
  • Ionic Interview Questions
  • Angular Js Projects
  • Best Front End Frameworks
  • Web Development Frameworks
  • Angular MCQ
  • Javascript vs Typescript Differences

918. How do you handle 404 and unauthorized routes?

您如何处理404和未授权的路由?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98657 | 官方: 否 | 付费: 否

答案:

  • Use a wildcard route for 404 pages
  • Use route guards to restrict access
  • Redirect unauthorized users to a dedicated unauthorized route

919. How do you configure routes in Angular using RouterModule.forRoot() vs forChild()?

您如何使用RouterModule.forRoot()与forChild()在Angular中配置路由?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9865a | 官方: 否 | 付费: 否

答案:

Angular provides two methods to register routes. - RouterModule.forRoot() is used in the root module (AppModule). It initializes the router service and should be called only once in the application.

Angular提供了两种注册路由的方法。- RouterModule.forRoot()用于根模块(AppModule)。它初始化路由器服务,并且应在应用程序中仅调用一次。
  • RouterModule.forChild() is used in feature modules, especially lazy loaded modules. It registers additional routes without creating a new router instance.
    Using forRoot() in multiple modules can lead to unexpected routing behavior and should be avoided.

    在多个模块中使用forRoot()可能导致意外的路由行为,应避免这样做。

920. What is the difference between path parameters and query parameters, and how do you read each?

路径参数和查询参数有什么区别,您如何读取每一种?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9865e | 官方: 否 | 付费: 否

答案:

Path parameters are mandatory values embedded in the URL path.

路径参数是嵌入在URL路径中的必需值。

Example URL:

示例 URL:

/users/10

/users/10

Access using: - ActivatedRoute.paramMap

使用方式: - ActivatedRoute.paramMap
Query parameters are optional and appear after ?.
查询参数是可选的,并出现在 ? 之后。

Example URL:

示例 URL:

/users?id=10&role=admin

/users?id=10&role=admin

Access using: - ActivatedRoute.queryParamMap

使用方式: - ActivatedRoute.queryParamMap
Path parameters are used for resource identification, while query parameters are commonly used for filters, sorting, and pagination.
路径参数用于资源标识,而查询参数通常用于过滤、排序和分页。

921. What is the difference between ActivatedRoute.snapshot and ActivatedRoute observables?

ActivatedRoute.snapshot 和 ActivatedRoute 可观察对象之间的区别是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98662 | 官方: 否 | 付费: 否

答案:

  • ActivatedRoute.snapshot provides a static value when the component is initialized.
  • ActivatedRoute observables (paramMap, queryParamMap) emit new values when route parameters change.

Snapshot is suitable for routes that do not change during the component lifecycle. Observables should be used when the same component instance handles multiple route changes.

Snapshot 适用于组件生命周期内路由不变化的情况。当同一组件实例处理多个路由变化时,应使用可观察对象。

922. What is pathMatch: 'full' and why is it important?

什么是 pathMatch: 'full',为什么它很重要?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98665 | 官方: 否 | 付费: 否

答案:

pathMatch defines how Angular matches a URL segment. - 'prefix' matches partial URLs and is the default.

pathMatch 定义了 Angular 如何匹配 URL 片段。 - 'prefix' 匹配部分 URL,是默认值。
  • 'full' matches the complete URL.
    pathMatch: 'full' is required for redirect routes, especially for empty paths, to prevent incorrect or infinite redirections.

    pathMatch: 'full' 对于重定向路由是必需的,尤其是对于空路径,以防止错误或无限重定向。

923. How do redirectTo routes work and what are common pitfalls?

redirectTo 路由如何工作,常见的陷阱有哪些?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98668 | 官方: 否 | 付费: 否

答案:

The redirectTo property redirects one route to another.

redirectTo 属性将一条路由重定向到另一条路由。

Common issues include: - Missing pathMatch: 'full'

常见问题包括: - 缺少 pathMatch: 'full'
  • Incorrect ordering of redirect routes
  • Redirect loops
  • Placing redirect routes after wildcard routes
    Redirect routes should always be defined before the wildcard route.

    重定向路由应始终定义在通配符路由之前。

924. What is a wildcard route (**) and where should it be placed?

什么是通配符路由(**),它应该放在哪里?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9866d | 官方: 否 | 付费: 否

答案:

A wildcard route matches any URL that does not match earlier route definitions.

通配符路由会匹配任何与之前路由定义不匹配的 URL。

Example:

示例:

{ path: '**', component: PageNotFoundComponent }

{ path: '**', component: PageNotFoundComponent }
It must be placed at the end of the route configuration to avoid overriding valid routes.
它必须放置在路由配置的末尾,以避免覆盖有效路由。

925. What are route guards and their differences?

什么是路由守卫及其区别?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98672 | 官方: 否 | 付费: 否

答案:

Route guards control navigation access. - CanActivate checks access to a route

路由守卫控制导航访问。 - CanActivate 检查对路由的访问权限
  • CanActivateChild checks access to child routes
  • CanDeactivate prevents leaving a route
  • CanLoad prevents loading lazy modules
  • CanMatch determines whether a route should be matched
    CanMatch is preferred over CanLoad in newer Angular versions.

    在新版 Angular 中,CanMatch 比 CanLoad 更受青睐。

926. What is a Resolver in Angular routing and when should it be used?

什么是 Angular 路由中的 Resolver,何时应使用它?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98675 | 官方: 否 | 付费: 否

答案:

A Resolver fetches data before route activation.

Resolver 在路由激活之前获取数据。

It is useful when: - The component requires data before rendering

在以下情况中有用: - 组件在渲染前需要数据
  • You want to avoid loading states inside components
  • SEO or initial page load experience matters
    Resolved data is accessed using ActivatedRoute.data.

    解析后的数据通过 ActivatedRoute.data 访问。

927. How do you implement lazy-loaded routes using loadChildren?

你如何使用 loadChildren 实现懒加载路由?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: coding
  • 分类: fullstack
  • id: 69b3792f58d557c902b98678 | 官方: 否 | 付费: 否

答案:

Lazy loading loads feature modules only when the route is accessed.

懒加载仅在访问路由时才加载功能模块。

Example:

示例:

{
path: 'admin',

path: 'admin',
loadChildren: () =>
loadChildren: () =>
import('./admin/admin.module').then(m => m.AdminModule)
import('./admin/admin.module').then(m => m.AdminModule)
}
Lazy loading improves application performance and reduces initial bundle size.
懒加载提高了应用性能并减小了初始包体积。

928. What are child routes and how does nested router-outlet work?

什么是子路由,嵌套的 router-outlet 是如何工作的?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9867b | 官方: 否 | 付费: 否

答案:

Child routes allow nested routing under a parent route.

子路由允许在父路由下进行嵌套路由。

The parent component template must contain for rendering child components.

父组件模板必须包含 才能渲染子组件。

This approach is commonly used for dashboards and layout based navigation.

这种方法常用于仪表盘和基于布局的导航。

929. What are auxiliary routes or named outlets?

什么是辅助路由或命名出口?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9867e | 官方: 否 | 付费: 否

答案:

Auxiliary routes allow multiple routes to be active simultaneously.

辅助路由允许多个路由同时处于激活状态。

They are implemented using named outlets and are useful for side panels, modals, or secondary views.

它们通过命名出口实现,适用于侧边面板、模态框或次级视图。

930. What is the difference between router.navigate() and navigateByUrl()?

router.navigate() 和 navigateByUrl() 有什么区别?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98681 | 官方: 否 | 付费: 否

答案:

  • navigate() accepts route segments and supports relative navigation.
  • navigateByUrl() accepts a full URL string.

navigate() is preferred for dynamic routes and parameters.

navigate() 更适用于动态路由和参数。

931. What are NavigationExtras and their use cases?

什么是 NavigationExtras 及其使用场景?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98684 | 官方: 否 | 付费: 否

答案:

NavigationExtras provide additional routing options.

NavigationExtras 提供额外的路由选项。

Common properties: - state for passing non-URL data

常见属性:- 用于传递非 URL 数据的 state
  • queryParamsHandling for merging or preserving query params
  • replaceUrl to avoid adding history entries
  • skipLocationChange to navigate without URL change

932. What is routerLinkActive and how is active state handled?

什么是 routerLinkActive,激活状态是如何处理的?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98687 | 官方: 否 | 付费: 否

答案:

routerLinkActive applies a CSS class when the linked route is active.

routerLinkActive 在链接的路由激活时应用一个 CSS 类。

For nested routes, routerLinkActiveOptions with exact: true helps avoid incorrect active states.

对于嵌套路由,使用带有 exact: true 的 routerLinkActiveOptions 有助于避免错误的激活状态。

933. How do you subscribe to Router events and why is it useful?

如何订阅 Router 事件,它为什么有用?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9868a | 官方: 否 | 付费: 否

答案:

Angular Router emits events such as NavigationStart and NavigationEnd.

Angular 路由器会发出诸如 NavigationStart 和 NavigationEnd 等事件。

Subscribing to these events is useful for: - Showing global loaders

订阅这些事件对于以下方面非常有用:- 显示全局加载器
  • Logging navigation
    Tracking analytics

    跟踪分析数据

934. What is RouteReuseStrategy and when is it useful?

什么是 RouteReuseStrategy,它何时有用?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9868d | 官方: 否 | 付费: 否

答案:

RouteReuseStrategy allows reuse of route components instead of destroying them.

RouteReuseStrategy 允许重用路由组件,而不是销毁它们。

It is commonly used in tab based interfaces to preserve component state and improve performance.

它通常用于基于标签页的界面中,以保留组件状态并提升性能。

935. How do you implement scroll position restoration and anchor scrolling?

如何实现滚动位置恢复和锚点滚动?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: coding
  • 分类: fullstack
  • id: 69b3792f58d557c902b98690 | 官方: 否 | 付费: 否

答案:

Scroll restoration and anchor scrolling are enabled in router configuration using router options.

滚动恢复和锚点滚动通过路由器配置中的路由器选项来启用。

This improves user experience when navigating between long pages.

这改善了在长页面之间导航时的用户体验。

936. How do you pass static data using route data?

如何使用路由数据传递静态数据?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98693 | 官方: 否 | 付费: 否

答案:

Static data can be passed using the data property in route configuration.

静态数据可以通过路由配置中的 data 属性来传递。

It is accessed in components using ActivatedRoute.data and is useful for metadata such as titles and permissions.

在组件中通过 ActivatedRoute.data 访问它,并且对于标题和权限等元数据非常有用。

937. How does the HTML element differ from CSS background-image? When should you use each?

HTML 元素与 CSS 背景图像有何不同?您应分别在何时使用它们?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58e8 | 官方: 否 | 付费: 否

答案:

The element is part of the HTML structure. It represents actual content and appears in the DOM.

元素是 HTML 结构的一部分。它代表实际内容,并出现在 DOM 中。

Key characteristics of : - It is semantic.

的主要特点:- 它是语义化的。
  • It supports alt text for accessibility.
  • It is indexed by search engines.
  • It supports srcset and sizes for responsive images.
  • It supports native lazy loading using loading="lazy".
  • It contributes to layout and takes up space automatically.
  • It prints by default.
    Example:

    示例:

<img src="photo.jpg" alt="Mountain landscape" loading="lazy">

<img src="photo.jpg" alt="山地景观" loading="lazy">
CSS background-image is purely presentational. It is applied through CSS.
CSS background-image 纯粹是表现性的。它通过CSS应用。

Example:

示例:

.card {

.card {
background-image: url("photo.jpg");
background-image: url("photo.jpg");
}
Key characteristics of background-image: - It is decorative.
background-image的关键特性:- 它是装饰性的。
  • It does not support alt text.
  • It is not indexed as content.
  • It allows multiple backgrounds on one element.
  • It requires explicit width and height on the element.
  • It does not print by default.
  • It supports background-size: cover and contain.
    A practical rule:

    一个实用规则:

If the image conveys meaning or content, use .

如果图片传达意义或内容,请使用。

If the image is decorative or purely aesthetic, use background-image.

如果图片是装饰性的或纯粹为了美观,请使用 background-image。

It is also possible to use with object-fit: cover; to achieve background-like behavior while keeping semantic and accessibility benefits.

还可以使用带有 object-fit: cover; 的 来实现类似背景图片的效果,同时保持语义化和可访问性的优势。

938. How do you style HTML form elements using CSS? What are the common challenges?

如何使用CSS样式化HTML表单元素?常见挑战有哪些?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58eb | 官方: 否 | 付费: 否

答案:

Form elements such as , , , and are partially controlled by the browser and operating system. Their appearance is not entirely defined by CSS, which creates styling challenges.

表单元素如 、 、 、 和 部分受浏览器和操作系统控制。它们的外观并非完全由CSS定义,这造成了样式化的挑战。

Common challenges include:

常见挑战包括:

Different browsers render form controls differently. A dropdown may look different in Chrome, Firefox, and Safari.

不同浏览器渲染表单控件的方式不同。一个 下拉菜单在Chrome、Firefox和Safari中的外观可能不同。

Some elements resist full styling control, such as: - option dropdown list

一些元素抵制完全样式化控制,例如:- 选项下拉列表
  • calendar picker
  • upload button
    To gain more control, developers often remove default styling using:

    为了获得更多控制,开发者通常移除默认样式,使用:

appearance: none;

appearance: none;
-webkit-appearance: none;
-webkit-appearance: none;
This removes native styling and allows custom CSS design.
这会移除原生样式并允许自定义 CSS 设计。

For checkboxes and radio buttons, a common technique is hiding the native control and styling a label or pseudo-element.

对于复选框和单选按钮,常用技术是隐藏原生控件并设置标签或伪元素的样式。

Example concept: - Set checkbox to opacity: 0 and position: absolute

示例概念:- 将复选框设置为 opacity:0 和 position: absolute
  • Style label::before as the visible checkbox
    Modern CSS provides the accent-color property, which simplifies styling of form controls:

    现代 CSS 提供了 accent-color 属性,它简化了表单控件的样式设置:

input {

input {
accent-color: #0066ff;
accent-color: #0066ff;
}
This works for checkboxes, radio buttons, range inputs, and progress elements.
这适用于复选框、单选按钮、范围输入和进度元素。

Useful pseudo-classes for form styling:

有用于表单样式设置的有用伪类:

:focus applies when an element receives focus.

:focus 在元素获得焦点时应用。

:focus-visible applies only when focus is triggered by keyboard navigation.

:focus-visible 仅在焦点由键盘导航触发时应用。

:placeholder-shown styles inputs when placeholder text is visible.

:placeholder-shown 当占位文本可见时样式化输入框。

:valid, :invalid, and :required allow styling based on validation state.

:valid、:invalid 和 :required 允许根据验证状态进行样式设置。

Example:

示例:

input:invalid {

input:invalid {
border: 2px solid red;
border: 2px solid red;(原文为代码,保持不变)
}
Styling forms requires handling browser inconsistencies and sometimes combining CSS with custom markup for full control.
样式化表单需要处理浏览器不一致性,有时还需将 CSS 与自定义标记相结合以实现完全控制。

939. What is the Shadow DOM and how does it affect CSS scoping?

什么是 Shadow DOM,它如何影响 CSS 作用域?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58ee | 官方: 否 | 付费: 否

答案:

Shadow DOM is a web standard that allows encapsulating a part of the DOM and its CSS inside a component. It creates a separate DOM tree that is isolated from the main document.

Shadow DOM 是一种 Web 标准,允许将 DOM 的一部分及其 CSS 封装在组件内部。它创建了一个与主文档隔离的独立 DOM 树。

When a shadow root is attached to an element using:

当使用以下方式将影子根附加到元素时:

element.attachShadow({ mode: "open" });

element.attachShadow({ mode: "open" });
a new DOM subtree is created. Styles written inside this shadow tree do not affect the main document, and styles from the main document do not leak into it.
会创建一个新的 DOM 子树。在此影子树中编写的样式不会影响主文档,主文档中的样式也不会泄漏到其中。

This solves one of the long-standing issues in CSS: global scope. Normally, CSS rules can affect any matching element anywhere in the page. Shadow DOM prevents that.

这解决了 CSS 中长期存在的问题:全局作用域。通常,CSS 规则可以影响页面中任何匹配的元素。Shadow DOM 阻止了这种情况。

However, there are important exceptions:

然而,有重要的例外情况:

Inherited properties such as color and font-family still pass into the Shadow DOM because they are inherited by nature.

诸如 color 和 font-family 等继承属性仍然会传入 Shadow DOM,因为它们本质上是继承的。

CSS custom properties (variables like --primary-color) also cross the shadow boundary. This allows theme control from outside.

CSS 自定义属性(如 --primary-color 等变量)也会跨越影子边界。这允许从外部进行主题控制。

Shadow DOM provides special selectors to control styling:

Shadow DOM 提供了特殊的选择器来控制样式:

:host is used inside the shadow tree to style the host element.

:host 在影子树内部用于样式化宿主元素。

:host {

:host {
display: block;
display: block;
}
:host-context(.dark-theme) allows styling based on an ancestor’s class outside the shadow root.
:host-context(.dark-theme) 允许基于影子根外部的祖先类进行样式化。

:host-context(.dark-theme) {

:host-context(.dark-theme) {
background: black;
background: black;
}
::part() allows external styling of specific parts that the component chooses to expose.
::part() 允许外部样式化组件选择公开的特定部分。

::part(button) {

::part(button) {
color: red;
color: red;
}
Many UI libraries and Web Components use Shadow DOM for style encapsulation. Even some native browser elements such as and internally use Shadow DOM for their built-in UI.
许多UI库和Web组件使用Shadow DOM进行样式封装。甚至一些原生浏览器元素(如和)在内部也使用Shadow DOM来实现其内置UI。

Shadow DOM ensures component-level styling isolation while still allowing controlled customization.

Shadow DOM确保组件级样式隔离,同时仍允许受控的定制化。

940. What are HTML data-* attributes and how can they be used with CSS?

什么是HTML data-* 属性,它们如何与CSS一起使用?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58f1 | 官方: 否 | 付费: 否

答案:

data-* attributes allow storing custom data directly inside HTML elements.

data-* 属性允许直接在HTML元素内部存储自定义数据。

Example:

示例:

<div data-status="active" data-count="5"></div>

<div data-status="active" data-count="5"></div>
These attributes do not affect layout or behavior by default. They simply store extra information.
这些属性默认不影响布局或行为。它们仅仅存储额外信息。

CSS can target them using attribute selectors:

CSS可以使用属性选择器来定位它们:

[data-status="active"] {

[data-status="active"] {
color: green;
color: green;
}
Partial matching is also possible:
也支持部分匹配:

[data-status^="act"] / starts with /

[data-status^="act"] / 以...开头 /
[data-status$="ive"] / ends with /
[data-status$="ive"] / 以...结尾 /
[data-status="tiv"] / contains */
[data-status="tiv"] / 包含... */
CSS also provides the attr() function to read attribute values inside pseudo-elements:
CSS还提供了attr()函数,用于在伪元素内部读取属性值。

.badge::after {

.badge::after {
content: attr(data-count);
content: attr(data-count);
}
This displays the value of data-count visually.
这会视觉上显示 data-count 的值。

Currently, attr() works reliably only with the content property. Using it for properties like width or font-size has limited browser support.

目前,attr() 仅可靠地支持 content 属性。将其用于 width 或 font-size 等属性时,浏览器支持有限。

JavaScript can access these attributes using:

JavaScript 可以使用以下方式访问这些属性:

element.dataset.status

element.dataset.status
A common use case is theming:
一个常见的用例是主题化:

[data-theme="dark"] {

[data-theme="dark"] {
background-color: black;
background-color: black;
color: white;
color: white;
}
Instead of adding multiple classes, the theme can be controlled using a single attribute.
与其添加多个类,不如使用单个属性来控制主题。

data-* attributes help connect HTML, CSS, and JavaScript in a structured and scalable way.

data-* 属性有助于以结构化和可扩展的方式连接 HTML、CSS 和 JavaScript。

941. How do HTML5 semantic elements affect CSS styling and accessibility?

HTML5 语义元素如何影响 CSS 样式和无障碍访问?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58f4 | 官方: 否 | 付费: 否

答案:

HTML5 introduced semantic elements such as:

HTML5 引入了语义元素,例如:

, , , , , , , , , , , ,
These elements provide meaning about the content they contain.

这些元素为其包含的内容提供了意义。

From a CSS perspective: - Most semantic elements behave like display: block by default.

从 CSS 的角度来看:- 大多数语义元素默认表现为 display: block。
  • They do not add extra visual styling.
  • They can be styled just like elements.
    Example:

    示例:

nav {

nav {
background-color: black;
background-color: black;
}
The main advantage is cleaner and more meaningful selectors.
主要优势是选择器更简洁且更有意义。

Instead of:

而不是:

.article-container .header-div

.article-container .header-div
You can write:
你可以这样写:

article > header

article > header
This reduces unnecessary class names and improves readability.
这减少了不必要的类名并提高了可读性。

From an accessibility perspective: - creates a navigation landmark.

从可访问性的角度来看:- 创建了导航地标。
  • defines the primary content.
  • may act as a banner.
  • represents complementary content.
    Screen readers use these elements to build a navigation outline.

    屏幕阅读器使用这些元素来构建导航大纲。

Search engines also use semantic structure to understand content hierarchy and importance.

搜索引擎也利用语义结构来理解内容的层次和重要性。

Semantic HTML improves structure without changing visual styling behavior.

语义化 HTML 在不改变视觉样式行为的情况下改善了结构。

942. What is the difference between HTML presentational attributes and CSS properties for styling?

HTML 展示属性和用于样式的 CSS 属性之间有什么区别?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58f7 | 官方: 否 | 付费: 否

答案:

HTML presentational attributes were older ways of styling elements directly inside HTML tags.

HTML 展示属性是在 HTML 标签内直接设置样式的旧方法。

Examples:

示例:

<body bgcolor="red">

<body bgcolor="red">
<p align="center">Text</p>

文本

<font size="5" color="blue">Hello</font>
你好
<img border="1">

These attributes mix structure and presentation in the same file.
这些属性在同一文件中混合了结构和表现。

CSS replaces these with proper styling rules:

CSS 用适当的样式规则替换这些:

body {

body {
background-color: red;
background-color: red;
}
p {
p {
text-align: center;
text-align: center;
}
font {
font {
font-size: 20px;
font-size: 20px;
color: blue;
color: blue;
}
img {
img {
border: 1px solid black;
border: 1px solid black;(原文为代码,保持不变)
}
Key differences: - HTML defines structure. CSS defines appearance.
关键区别:- HTML定义结构。CSS定义外观。
  • CSS allows one rule to style multiple elements.
  • CSS supports media queries and responsive design.
  • CSS provides cascade and specificity control.
  • CSS is easier to maintain and update.
    Many presentational attributes such as bgcolor, align, , and are deprecated in HTML5.

    许多表现性属性(如 bgcolor、align、 和 )在HTML5中已被废弃。

Some attributes still remain valid, such as: - width and height on (helps prevent layout shift)

某些属性仍然有效,例如:在 上的 width 和 height(有助于防止布局偏移)
  • type on
    Modern development separates structure (HTML) and presentation (CSS) completely.

    现代开发完全分离了结构(HTML)与表现(CSS)。

943. What is the Critical Rendering Path? How do HTML and CSS work together to render a web page?

什么是关键渲染路径?HTML 和 CSS 如何共同协作来渲染网页?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba58fa | 官方: 否 | 付费: 否

答案:

The Critical Rendering Path (CRP) is the sequence of steps the browser follows to turn HTML and CSS into visible pixels on the screen.

关键渲染路径(CRP)是浏览器将 HTML 和 CSS 转换为屏幕上可见像素所遵循的步骤序列。

When a browser loads a webpage, it does not immediately display content. It goes through a structured process:

当浏览器加载网页时,它不会立即显示内容,而是经历一个结构化的过程:
  1. HTML Parsing -> DOM Tree

    1. HTML 解析 -> DOM 树

The browser reads the HTML file and converts it into a Document Object Model (DOM). The DOM is a tree structure representing all HTML elements.

浏览器读取 HTML 文件并将其转换为文档对象模型(DOM)。DOM 是表示所有 HTML 元素的树结构。
  1. CSS Parsing -> CSSOM Tree

    1. CSS 解析 -> CSSOM 树

The browser reads CSS files and builds the CSS Object Model (CSSOM), which contains all style rules.

浏览器读取 CSS 文件并构建 CSS 对象模型(CSSOM),其中包含所有样式规则。
  1. DOM + CSSOM -> Render Tree

    1. DOM + CSSOM -> 渲染树

The DOM and CSSOM combine to form the Render Tree. Only visible elements are included here.

DOM 和 CSSOM 结合形成渲染树。这里只包含可见元素。

Elements with display: none are excluded.

具有 display: none 的元素被排除在外。

Elements with visibility: hidden remain in the tree.

具有 visibility: hidden 的元素仍保留在树中。
  1. Layout (Reflow)

    1. 布局(回流)

The browser calculates the position and size of each element.

浏览器计算每个元素的位置和大小。
  1. Paint

    1. 绘制

The browser fills pixels - colors, borders, text, shadows, etc.

浏览器填充像素——颜色、边框、文本、阴影等。
  1. Composite

    1. 合成

Layers are merged in the correct stacking order (z-index, transforms, etc.).

图层按正确的堆叠顺序(z-index、变换等)合并。

CSS is render-blocking because the browser cannot paint anything until the CSSOM is fully constructed. Styles affect layout and appearance, so rendering waits for CSS to finish loading.

CSS 会阻塞渲染,因为浏览器在 CSSOM 完全构建之前无法绘制任何内容。样式影响布局和外观,因此渲染会等待 CSS 加载完成。

Common optimization strategies: - Inline critical CSS for above-the-fold content

常见优化策略:- 为首屏内容内联关键 CSS
  • Defer non-critical CSS
  • Reduce unnecessary DOM depth
  • Avoid forced layout recalculations
    The Critical Rendering Path explains why CSS placement and loading strategy directly impact performance.

    关键渲染路径解释了为何 CSS 的放置位置和加载策略直接影响性能。

944. What is the CSS pointer-events property? What are its use cases?

什么是 CSS 的 pointer-events 属性?它有哪些用例?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba5916 | 官方: 否 | 付费: 否

答案:

The pointer-events property controls whether an element responds to mouse and touch interactions.

pointer-events 属性控制元素是否响应鼠标和触摸交互。

Basic values: - auto - default behavior

基本值:- auto - 默认行为
  • none - element does not receive pointer events
    When pointer-events: none; is applied, clicks pass through the element to whatever is behind it.

    当应用 pointer-events: none; 时,点击会穿透该元素到达其背后的元素。

Example:

示例:

.overlay {

.overlay {
pointer-events: none;
pointer-events: none;
}
Common use cases:
常见用例:

Disabling interaction visually:

视觉上禁用交互:

.btn--disabled {

.btn--disabled {
pointer-events: none;
pointer-events: none;
opacity: 0.5;
opacity: 0.5;
}
Creating decorative overlays that should not block clicks underneath.
创建不应阻挡下方点击的装饰性叠加层。

Disabling links without removing the href:

在不移除 href 的情况下禁用链接:

a.inactive {

a.inactive {
pointer-events: none;
pointer-events: none;
}
Creating watermarks or transparent UI layers that should not capture clicks.
创建不应捕获点击的水印或透明 UI 层。

Important caveats:

重要注意事项:

pointer-events: none does not prevent keyboard interaction. The element can still receive focus and be activated using the keyboard. For complete disabling, use: - tabindex="-1"

pointer-events: none 不会阻止键盘交互。该元素仍可获得焦点并通过键盘激活。要完全禁用,请使用:- tabindex="-1"
  • aria-disabled="true"
    Child elements can override the parent’s setting. If a parent has pointer-events: none, but a child has pointer-events: auto, the child will still respond to interaction.

    子元素可以覆盖父元素的设置。如果父元素具有 pointer-events: none,但子元素具有 pointer-events: auto,则子元素仍会响应交互。

In SVG, additional values exist such as visiblePainted, stroke, fill, and others.

在 SVG 中,还存在其他值,如 visiblePainted、stroke、fill 等。

pointer-events is frequently used in UI layering and interaction control, especially in complex layouts.

pointer-events 常用于 UI 分层和交互控制,尤其是在复杂布局中。

945. What are CSS text-overflow, word-wrap, and overflow-wrap properties? How do you handle text overflow?

什么是 CSS 的 text-overflow、word-wrap 和 overflow-wrap 属性?如何处理文本溢出?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba5919 | 官方: 否 | 付费: 否

答案:

Text overflow happens when content exceeds the available space in its container. CSS provides multiple properties to control how text behaves.

当内容超出其容器的可用空间时,就会发生文本溢出。CSS 提供了多种属性来控制文本的行为。

text-overflow controls how hidden overflowed text is visually indicated.

text-overflow 控制隐藏的溢出文本如何以视觉方式呈现。

Common values: - clip - cuts the text abruptly (default)

常见值:- clip - 直接截断文本(默认值)
  • ellipsis - adds "..." at the end
    For text-overflow: ellipsis to work, three conditions must be met:

    要使 text-overflow: ellipsis 生效,必须满足三个条件:

.box {

.box {
overflow: hidden;
overflow: hidden;
white-space: nowrap;
white-space: nowrap;
text-overflow: ellipsis;
text-overflow: ellipsis;
}
Without overflow: hidden and white-space: nowrap, ellipsis will not appear.
如果没有overflow: hidden和white-space: nowrap,省略号将不会出现。

For multi-line truncation, the common pattern is:

对于多行截断,常见模式是:

.box {

.box {
display: -webkit-box;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
-webkit-box-orient: vertical;
overflow: hidden;
overflow: hidden;
}
This limits text to three lines and adds ellipsis. Browser support varies slightly, but it works in modern browsers.
这会将文本限制为三行并添加省略号。浏览器支持略有差异,但在现代浏览器中都能正常工作。

overflow-wrap (formerly word-wrap) controls whether long words can break inside themselves.

overflow-wrap(旧称word-wrap)控制长单词是否可以在内部断开。

overflow-wrap: break-word;

overflow-wrap: break-word;
This prevents long URLs or continuous strings from overflowing their container.
这可以防止长URL或连续字符串溢出其容器。

word-break gives more aggressive control: - break-all breaks between any characters.

word-break提供更激进的保护:- break-all在任意字符之间断开。
  • keep-all prevents breaking in certain languages like CJK.
    white-space controls how whitespace and line breaks behave: - normal - collapses spaces and allows wrapping

    white-space 控制空白符和换行的行为: - normal - 折叠空格并允许换行
  • nowrap - prevents wrapping
  • pre - preserves spaces and line breaks
  • pre-wrap - preserves spaces but allows wrapping
  • pre-line - collapses spaces but preserves line breaks
    The hyphens property can automatically insert hyphenation points:

    hyphens 属性可以自动插入连字符断点:

p {

p {
hyphens: auto;
hyphens: auto;
}
This works best when the lang attribute is set correctly on the HTML element.
当 HTML 元素上正确设置了 lang 属性时,效果最佳。

Handling text overflow properly prevents layout breakage and improves readability, especially in dynamic content systems.

正确处理文本溢出可以防止布局破坏并提高可读性,尤其是在动态内容系统中。

946. What is the difference between max-width and width? Why does max-width matter for responsive design?

max-width 和 width 之间有什么区别?为什么 max-width 对响应式设计很重要?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba591c | 官方: 否 | 付费: 否

答案:

The width property sets the exact width of an element. That width can be fixed (like 1200px) or relative (like 80%).

width 属性设置元素的精确宽度。该宽度可以是固定的(如 1200px)或相对的(如 80%)。

Example:

示例:

.container {

.container {
width: 1200px;
width: 1200px;
}
Here, the container will always try to be 1200px wide. On small screens, this causes horizontal scrolling because the element cannot shrink below that value.
这里,容器会始终尝试达到 1200px 宽。在小屏幕上,这会导致水平滚动,因为元素无法缩小到该值以下。

max-width works differently. It sets an upper limit. The element can become smaller, but it will never grow larger than the specified value.

max-width 的工作方式不同。它设置了一个上限。元素可以变得更小,但永远不会超过指定的值。

Example:

示例:

.container {

.container {
width: 100%;
width: 100%;
max-width: 1200px;
最大宽度:1200px;
}
This means: - On small screens, the container becomes 100% of the screen width.
这意味着: - 在小屏幕上,容器会变成屏幕宽度的 100%。
  • On large screens, it stops growing once it reaches 1200px.
  • It stays centered if combined with margin: 0 auto;.
    Full responsive pattern:

    完全响应式模式:

.container {

.container {
width: 100%;
width: 100%;
max-width: 1200px;
最大宽度:1200px;
margin: 0 auto;
外边距:0 auto;
}
This creates a layout that is fluid on mobile and capped on large screens without needing media queries.
这创建了一种在移动设备上流畅、在大屏幕上封顶的布局,而无需使用媒体查询。

Important behavior:

重要行为:

If both width and max-width are set and the width exceeds max-width, the max-width value wins.

如果同时设置了宽度和最大宽度,且宽度超过最大宽度,则最大宽度值优先。

Example:

示例:

.box {

.box {
width: 1500px;
宽度:1500px;
max-width: 1200px;
最大宽度:1200px;
}
The final width will be 1200px.
最终宽度将是 1200px。

Common responsive image pattern:

常见响应式图片模式:

img {

img {
max-width: 100%;
最大宽度:100%;
height: auto;
高度:自动;
}
This ensures images never overflow their container and scale proportionally.
这确保了图片永远不会超出其容器,并按比例缩放。

Related properties: - min-width sets a lower limit.

相关属性:- min-width 设定了一个下限。
  • min-height and max-height work the same way vertically.
    One detail to remember:

    需要记住的细节:

Percentage-based max-width is relative to the containing block. Viewport units like vw are relative to the viewport.

基于百分比的 max-width 是相对于包含块而言的。像 vw 这种视口单位则是相对于视口的。

max-width is essential for responsive design because it prevents layout overflow while keeping content fluid.

max-width 对响应式设计至关重要,因为它能防止布局溢出,同时保持内容流动。

947. What is the CSS transform property? Explain all transform functions.

什么是 CSS transform 属性?解释所有 transform 函数。
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: coding
  • 分类: fullstack
  • id: 69b37a5858d557c902ba5920 | 官方: 否 | 付费: 否

答案:

The transform property applies geometric transformations to elements. It changes how an element appears visually without affecting the document flow.

transform 属性对元素应用几何变换。它改变元素的视觉效果,而不影响文档流。

2D transform functions:

2D 变换函数:

translate(x, y) moves an element. translateX() and translateY() move along a single axis.

translate(x, y) 移动元素。translateX() 和 translateY() 沿单个轴移动。

transform: translate(50px, 20px);

transform: translate(50px, 20px);
rotate(angle) rotates an element.
rotate(angle) 旋转元素。

transform: rotate(45deg);

transform: rotate(45deg);
scale(x, y) resizes an element.
scale(x, y) 改变元素的大小。

transform: scale(1.5);

transform: scale(1.5);
skew(x-angle, y-angle) tilts an element.
skew(x-angle, y-angle) 倾斜元素。

transform: skew(20deg);

transform: skew(20deg);
3D transform functions: - rotateX(), rotateY(), rotateZ()
3D变换函数:- rotateX(), rotateY(), rotateZ()
  • translate3d(x, y, z)
  • scale3d()
  • perspective()
    Multiple transforms can be chained:

    多个变换可以链式使用:

transform: translateX(50px) rotate(45deg) scale(1.2);

变换:translateX(50px) rotate(45deg) scale(1.2);
Transforms are applied from right to left.
变换从右到左依次应用。

The transform-origin property changes the pivot point.

transform-origin 属性可更改旋转中心点。

transform-origin: top left;

变换原点:左上角;
By default, the origin is at the center.
默认情况下,原点位于中心位置。

From a performance perspective, transform and opacity are the safest properties to animate. They do not trigger layout recalculation and can be handled by the GPU, making them smoother than properties like width or margin.

从性能角度看,transform 和 opacity 是最适合动画的属性。它们不会触发布局重算,可由GPU处理,因此比 width 或 margin 等属性的动画更流畅。

948. How do CSS media queries work? Explain breakpoints and mobile-first approach.

CSS 媒体查询如何工作?请解释断点和移动优先方法。
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba5923 | 官方: 否 | 付费: 否

答案:

CSS media queries apply styles only when certain conditions are met.@media (condition) { / rules / }@media (min-width: 768px) { .container { display: flex; } }@media (orientation: landscape)

CSS 媒体查询仅在满足特定条件时应用样式。@media (condition) { / 规则 / }@media (min-width: 768px) { .container { display: flex; } }@media (orientation: landscape)

@media (hover: hover)

@media (hover: hover)
Conditions can be combined:
条件可以组合使用:

@media (min-width: 768px) and (max-width: 1024px)

@media (min-width: 768px) and (max-width: 1024px)
Common breakpoint ranges: - 320px - small mobile
常见断点范围:- 320px - 小型手机
  • 480px - standard mobile
  • 768px - tablet
  • 1024px - laptop
  • 1200px - desktop
  • 1440px - large desktop
    Mobile-first approach:

    移动优先方法:

Base CSS targets small screens.

基础CSS针对小屏幕设计。

Enhancements are added using min-width media queries.

通过最小宽度媒体查询来添加增强效果。

Example:

示例:

.container {

.container {
display: block;
display: block;
}
@media (min-width: 768px) {
@media (min-width: 768px) {
.container {
.container {
display: flex;
display: flex;
}
}
This keeps the base design simple and progressively enhances layout for larger screens.
这保持了基础设计的简洁性,并逐步增强了更大屏幕的布局。

Desktop-first approach does the opposite by using max-width queries to simplify layouts for smaller screens.

桌面优先方法则相反,使用最大宽度查询来简化较小屏幕的布局。

Mobile-first is generally preferred because it prioritizes performance and progressive enhancement.

移动优先通常更受青睐,因为它优先考虑性能和渐进增强。

This applies styles only when the viewport is 768px or wider.

这仅在视口宽度为768像素或更宽时应用样式。

Feature-based queries are also possible:

基于功能的查询也是可能的:

Most common type is width-based:

最常见的类型是基于宽度的:

Basic syntax:

基本语法:

949. What is BEM (Block Element Modifier) methodology in CSS? Why is it popular?

什么是CSS中的BEM(块元素修饰符)方法论?为什么它很流行?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba5926 | 官方: 否 | 付费: 否

答案:

BEM is a naming convention for CSS classes that creates a clear structure for components. It stands for Block, Element, Modifier.block__element--modifier.card .menu .form .card__title .card__image .menu__item .card--featured .menu__item--active .button--large

BEM是一种CSS类命名约定,为组件创建清晰的结构。它代表块、元素、修饰符。.block__element--modifier.card .menu .form .card__title .card__image .menu__item .card--featured .menu__item--active .button--large

Example in HTML:

HTML中的示例:

<div class="card card--featured">

Why BEM is widely used: - Class names describe structure clearly.
为什么BEM被广泛使用:- 类名清晰地描述了结构。

  • Selectors usually remain single-class (low specificity).
  • It avoids deep nesting and overly complex selectors.
  • Naming conflicts are minimized because blocks are self-contained.
  • It scales well in large projects where many developers work together.
    Alternative methodologies exist, such as OOCSS, SMACSS, and utility-first approaches, but BEM remains popular because it is simple, readable, and framework-independent.

    存在其他方法论,如OOCSS、SMACSS和实用优先方法,但BEM因其简单、可读且与框架无关而仍然流行。

Modifier represents a variation or state.

修饰符表示变化或状态。

Element represents a part of the block that depends on it.

元素表示依赖于块的组成部分。

Block represents a standalone component.

块表示独立的组件。

Example:

示例:

Format:

格式:

950. What are CSS transitions? How do they differ from CSS animations?

什么是CSS过渡?它们与CSS动画有何不同?
  • 知识点: 前端 (主题: css, frontend;标签: interviewbit, css, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37a5858d557c902ba5929 | 官方: 否 | 付费: 否

答案:

CSS transitions animate the change of a property between two states. The animation happens when a property value changes, for example on :hover, :focus, or when a class is added or removed.transition: property duration timing-function delay;.button { background: blue; transition: background 0.3s ease; } .button:hover { background: red; }@keyframes slide { 0% { left: 0; } 50% { left: 50%; } 100% { left: 100%; } } .box { animation: slide 2s ease infinite; }

CSS过渡在两个状态之间对属性的变化进行动画处理。当属性值改变时,动画发生,例如在:hover、:focus或添加或移除类时。transition: property duration timing-function delay;.button { background: blue; transition: background 0.3s ease; } .button:hover { background: red; }@keyframes slide { 0% { left: 0; } 50% { left: 50%; } 100% { left: 100%; } } .box { animation: slide 2s ease infinite; }

Animations can: - Run automatically

动画可以:- 自动运行
  • Loop infinitely
  • Reverse direction
  • Pause and resume
  • Define multiple stages
    Key differences: - Transitions require a state change to trigger.

    关键区别:- 过渡需要状态变化来触发。
  • Animations can start automatically.
  • Transitions move between two states only.
  • Animations can define multiple keyframes.
  • Transitions cannot loop.
  • Animations can repeat using animation-iteration-count.
    Both transitions and animations perform best when animating transform and opacity, as those properties avoid layout recalculation.

    过渡和动画在动画化transform和opacity时表现最佳,因为这些属性避免了布局重新计算。

When the button is hovered, the background color smoothly changes from blue to red over 0.3 seconds.

当按钮被悬停时,背景颜色在0.3秒内从蓝色平滑变为红色。

Timing functions control acceleration: - ease (default)

定时函数控制加速: - ease(默认)
  • linear
  • ease-in
  • ease-out
  • ease-in-out
  • cubic-bezier()
    CSS animations are more powerful. They use @keyframes and allow multiple intermediate steps.

    CSS 动画更强大。它们使用 @keyframes 并允许多个中间步骤。

Example:

示例:

Example:

示例:

Basic syntax:

基本语法:

951. Can we display a web page inside a web page or Is nesting of webpages possible?

我们能否在网页内显示网页,或者网页嵌套是否可行?
  • 知识点: 前端 (主题: html, frontend;标签: interviewbit, html, topic-specific, frontend)
  • 类型: technical | 难度: medium | 子类型: concept
  • 分类: fullstack
  • id: 69b37b3a58d557c902bae227 | 官方: 否 | 付费: 否

答案:

Yes, we can display a web page inside another HTML web page. HTML provides a tag using which we can achieve this functionality.

是的,我们可以在另一个HTML网页中显示一个网页。HTML提供了一个标签,我们可以使用它来实现这个功能。
注意Safari一下,会报错:

Blocked a frame with origin “http://localhost:10001” from accessing a frame with origin “http://localhost:10000“. Protocols, domains, and ports must match.

阻止了来源为“http://localhost:10001”的框架访问来源为“http://localhost:10000”的框架。协议、域名和端口必须匹配。
避免该错误,可以在Safari浏览器中勾选开发菜单==>停用跨域限制。或者只能使用服务器端转存的方式实现,因为Safari浏览器默认只支持CORS(Cross-Origin Resource Sharing)跨域请求。
方式六:修改document.domain跨子域
前提条件:这两个域名必须属于同一个基础域名!而且所用的协议,端口都要一致,否则无法利用document.domain进行跨域,所以只能跨子域
在根域范围内,允许把domain属性的值设置为它的上一级域。例如,在”aaa.xxx.com”域内,可以把domain设置为 “xxx.com” 但不能设置为 “XXX.com Porn - Free PORNO videos” 或者”com”。
现在存在两个域名aaa.xxx.com和bbb.xxx.com。在aaa下嵌入bbb的页面,由于其document.name不一致,无法在aaa下操作bbb的js。可以在aaa和bbb下通过js将document.name = 'xxx.com';设置一致,来达到互相访问的作用。
方式七:WebSocket(网络套接字)
WebSocket protocol(网络套接字协议) 是HTML5(超文本标记语言第五版)一种新的协议。它实现了浏览器与服务器全双工通信,同时允许跨域通讯,是server push(服务器推送)技术的一种很棒的实现。相关文章,请查看:WebSocket、WebSocket-SockJS
需要注意:WebSocket对象不支持DOM(文档对象模型) 2级事件侦听器,必须使用DOM(文档对象模型) 0级语法分别定义各个事件。
方式八:代理
同源策略是针对浏览器端进行的限制,可以通过服务器端来解决该问题
DomainA客户端(浏览器) ==> DomainA服务器 ==> DomainB服务器 ==> DomainA客户端(浏览器)
来源:blog.csdn.net/ligang2585116/article/details/73072868

1164. XML(可扩展标记语言)文档定义有几种形式?它们之间有何本质区别?解析XML(可扩展标记语言)文档有哪几种方式?

  • 知识点: 前端 / 编程语言基础 (主题: xml, java;标签: DTD, Schema, DOM, SAX, StAX)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696700d8fa809e6d389eba6a | 官方: 是 | 付费: 否

答案:

答案a: 两种形式 dtd schema,b: 本质区别:schema本身是xml的,可以被XML(可扩展标记语言)解析器解析(这也是从DTD上发展schema的根本目的),c:有DOM(文档对象模型),SAX(简单应用程序接口),STAX(流式应用程序接口)等
DOM:处理大型文件时其性能下降的非常厉害。这个问题是由DOM(Document Object Model)的树结构(tree structure)所造成的,这种结构占用的内存较多,而且DOM必须在解析文件之前把整个文档装入内存,适合对XML(Extensible Markup Language)的随机访问(random access)
SAX(Simple API for XML):不现于DOM,SAX是事件驱动型(event-driven)的XML解析方式。它顺序读取XML文件,不需要一次全部装载整个文件。当遇到像文件开头,文档结束,或者标签开头与标签结束时,它会触发一个事件,用户通过在其回调事件中写入处理代码来处理XML文件,适合对XML的顺序访问(sequential access)
STAX:Streaming API for XML (StAX)

STAX:用于 XML 的流式 API(StAX)

1165. 什么是 React.cloneElement?它与 this.props.children 有什么区别?

  • 知识点: 前端 (主题: react, composition, frontend;标签: cloneElement, children, ref, Props Merge)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 69676958fa809e6d38aac1c7 | 官方: 是 | 付费: 否

答案:

答案
React.cloneElement 只能在我们的 child 是一个单一 React element(React元素)时工作。对于绝大多数情况,{this.props.children} 是更好的解决方案。

在一些更高级的场景中,cloneElement 会很有用:父组件传入一个 element,而子组件需要修改这个 element 上的一些 props(属性),或者添加诸如 ref(引用,用于访问实际 DOM(Document Object Model)元素)之类的能力。

React.cloneElement 会 clone 并返回一个新的 React element,它以传入的 element 作为起点。返回的 element 会保留原 element 的 props,并把新的 props 做浅合并(shallowly merged)。新的 children(子元素)会替换现有 children;原 element 的 key 和 ref 会被保留。

1166. 什么是 CSS(Cascading Style Sheets)选择器优先级(specificity),它是如何工作的?

  • 知识点: 前端 (主题: css;标签: specificity)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696eef3eb43a3b362ff54907 | 官方: 是 | 付费: 否

答案:

答案浏览器会根据 CSS 规则的优先级决定元素最终显示哪些样式。假设浏览器已经找到了匹配某个元素的所有规则,那么会为每条规则计算四个逗号分隔的值 a、b、c、d:

  • a:是否使用了行内样式。如果声明是元素上的行内样式,a 为 1,否则为 0。
  • b:ID 选择器数量。
  • c:class、属性选择器、伪类选择器数量。
  • d:标签选择器、伪元素选择器数量。
    最终的优先级不是一个简单的分数,而是一个可以按列比较的矩阵。比较选择器时,从左到右逐列比较每一列的最高值。比如 b 列的值会覆盖 c 和 d 列的值,无论后两列多大。因此 0,1,0,0 会大于 0,0,10,10。
    当优先级相同:后出现的规则生效。如果你在样式表中(无论内联还是外链)写了两次同样的规则,那么更靠下的一条离被样式化的元素更近,被认为更具体,因此会被应用。
    我会写低优先级的 CSS 规则,以便在需要时更容易被覆盖。在写 CSS UI(User Interface)组件库代码时,保持低优先级很重要,这样库的使用者无需为了提高优先级而写过于复杂的选择器或诉诸 !important(重要声明)。

1167. 请描述块级格式化上下文(BFC,Block Formatting Context)以及它是如何工作的?

  • 知识点: 前端 (主题: css;标签: bfc, block-formatting-context, margin-collapsing)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696ef073b43a3b362ff56f2c | 官方: 是 | 付费: 否

答案:

答案块级格式化上下文(BFC)是网页 CSS 可视化渲染的一部分,用于布局块级盒子。浮动元素、绝对定位元素、inline-block(内联块)、table-cell(表格单元格)、table-caption(表格标题),以及 overflow 不是 visible 的元素(除非该值被传播到视口)都会建立新的块级格式化上下文。
BFC 是满足以下至少一个条件的 HTML(HyperText Markup Language)盒子:

  • float 的值不是 none。
  • position 的值既不是 static 也不是 relative。
  • display 的值是 table-cell、table-caption、inline-block、flex 或 inline-flex。
  • overflow 的值不是 visible。
    在 BFC 中,每个盒子的左外边缘会贴着包含块的左边缘(对于从右到左的排版,右边缘贴着)。
    在 BFC 中,相邻块级盒子之间的垂直外边距会发生折叠。更多内容可参考 margin 折叠(collapsing margins)。

1168. 编写高效 CSS 有哪些“坑”(gotchas)?

  • 知识点: 前端 (主题: css;标签: selector-performance, bem, reflow, repaint)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696ef1d6b43a3b362ff5be88 | 官方: 是 | 付费: 否

答案:

答案- 首先要理解:浏览器从最右侧(关键选择器(key selector))向左匹配选择器(selector)。浏览器会先根据关键选择器在 DOM(Document Object Model)中筛选元素,再向上遍历其父元素(parent element)来判断是否匹配。选择器链(selector chain)越短,浏览器越快判断元素是否匹配。因此应避免把标签选择器(type selector)和通配选择器(universal selector)作为关键选择器,因为它们会匹配大量元素,浏览器需要做更多工作来判断父级是否匹配。

  • BEM(Block Element Modifier)方法论建议:一切都使用单一 class;如果需要层级关系,就把层级信息写进 class 名称里,这会让选择器天然更高效、也更容易覆盖。
  • 注意哪些 CSS 属性会触发 reflow、repaint、compositing。尽量避免编写会改变布局(触发 reflow)的样式。

1169. 你会如何提升网站加载速度?请给出有条理的优化清单。

  • 知识点: 前端 / 后端 / 系统设计/架构 / UI/UX 设计 (主题: web-performance, frontend, backend;标签: performance, cdn, cache, web-vitals)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f1141120fcc15911594be | 官方: 是 | 付费: 否

答案:

答案按层优化:网络(CDN(Content Delivery Network)、压缩、缓存(caching)、HTTP/2/3)、资源(图片/代码优化、懒加载(lazy loading)、减少第三方)、渲染(关键渲染路径(critical rendering path)、预加载(preload)/预连接(preconnect))、后端(降低 TTFB(Time to First Byte)、缓存、DB 与 API 优化)。用 LCP(Largest Contentful Paint)/INP(Interaction to Next Paint)/CLS(Cumulative Layout Shift)、TTFB 与瀑布图(waterfall chart)验证,并持续监控回归。

1170. Svelte、Vue、React 在“更新粒度(update granularity)”上有什么典型差异?

  • 知识点: 前端 (主题: react, vue, javascript;标签: svelte, reactivity, rendering)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a5120fcc1591165685 | 官方: 是 | 付费: 否

答案:

答案一种常见理解是:Svelte 倾向于在编译期(compile time)把状态与 DOM 绑定到更细的“元素级(element-level)”更新;Vue 通过响应式依赖追踪(reactive dependency tracking)实现“组件级(component-level)”精准更新;React 更偏“应用级(application-level)”从根触发协调(reconciliation)与对比,依靠调度(scheduling)(并发(concurrency)/时间切片(time slicing))与显式缓存(memo/useMemo)来减少不必要渲染(rendering)。

1171. React 在高频交互场景下为什么容易出现性能瓶颈(performance bottleneck)?常见优化思路有哪些?

  • 知识点: 前端 (主题: react, vue, javascript;标签: performance, re-render, memo, throttle)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656b6 | 官方: 是 | 付费: 否

答案:

答案高频事件(拖拽(drag)、resize、输入联动)会触发大量状态更新(state update)与协调(reconciliation)开销,导致 diff/commit 压力上升。常见优化:减少受控范围(拆分状态到更小粒度)、避免无意义重渲染(React.memo/useMemo/useCallback)、事件节流(throttling)/防抖(debouncing)、以及在极端场景用直接 DOM/Canvas/WebGPU绕开频繁的 React 渲染路径(rendering path)。

1172. Vue 的响应式(reactivity)与 React 的 Virtual DOM diff,压力点分别在哪里?

  • 知识点: 前端 (主题: react, vue, javascript;标签: reactivity, virtual-dom, diff)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656bd | 官方: 是 | 付费: 否

答案:

答案Vue 的主要压力在数据侧:依赖收集(dependency collection)、追踪与深层结构的监听/递归可能带来成本;React 的主要压力在UI 协调(reconciliation)侧:状态变化后通过比较虚拟树(virtual tree)决定变更。Vue 更强调“知道哪些组件依赖了哪些数据”,React 更通用但可能需要开发者用 memo 等手段减少不必要的对比与重渲染(re-rendering)。

1173. React 与 Vue 的 diff 算法(或更新策略)有哪些典型差异?

  • 知识点: 前端 (主题: react, vue, javascript;标签: diff, lis, patch)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656c6 | 官方: 是 | 付费: 否

答案:

答案React 常见描述是“同层递归对比”,记录差异生成 patch(或副作用(side effect))后再统一提交;Vue2 子节点对比常用双端指针(double-ended pointer)提升移动/复用效率;Vue3 结合编译期静态标记(static marking)与更高效的数据结构(如 Map)并引入 LIS(Longest Increasing Subsequence,最长递增子序列)优化子节点重排,从而减少无谓比较与 DOM 操作。

1174. 函数组件(function component)每次执行上下文都“重新创建”,React 用什么方式记录 Hooks 的状态?

  • 知识点: 前端 (主题: react, vue, javascript;标签: fiber, hooks, memoizedState)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc15911656fe | 官方: 是 | 付费: 否

答案:

答案React 通过Fiber 数据结构(Fiber data structure)为每个组件实例保存状态;Hooks 会按声明顺序形成链表(linked list)/序列挂在对应 Fiber 上(例如 memoizedState 等字段)。每次渲染时,React 依据“调用顺序一致”来定位到对应 hook 节点,从而读写该 hook 的状态与更新队列(update queue)。

1175. React 中 setState / useState 更新是同步(synchronous)还是异步(asynchronous)?为什么常感觉“拿不到最新值”?

  • 知识点: 前端 (主题: react, vue, javascript;标签: setState, batching, closure)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc1591165705 | 官方: 是 | 付费: 否

答案:

答案很多场景下(合成事件(synthetic event)、生命周期(lifecycle)/Effect(useEffect)回调中)更新会被批处理(batching),表现为“当下读不到最新值”。本质并非一定是异步实现,而是更新在提交(commit)前不会立刻反映到当前闭包(closure)中的 state。解决思路:使用函数式更新(functional update)(setState(prev=>...))、使用 ref 保存可变值,或在下一次渲染/Effect 中读取最新状态。

1176. 为什么 useContext(使用上下文)往往不能做到“精准更新”?常见优化手段有哪些?

  • 知识点: 前端 (主题: react, vue, javascript;标签: useContext, rendering, state-management)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc159116570e | 官方: 是 | 付费: 否

答案:

答案Context(上下文)的 value(值)变化会触发订阅该 Context(上下文)的组件重渲染(re-render);如果把一个大对象作为 value(值),任何字段变化都可能导致广泛更新。优化思路:拆分多个 Context(上下文)、将 value(值)做 memo(记忆化)(稳定引用)、或引入 selector(选择器)/外部状态库(external state library)实现按字段订阅,从而减少无关组件重渲染。

1177. useCallback(使用回调)和 useMemo(使用记忆化)的区别是什么?为什么说 useCallback(使用回调)需要“配套使用”才有价值?

  • 知识点: 前端 (主题: react, vue, javascript;标签: useCallback, useMemo, React.memo)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 696f18a6120fcc159116571d | 官方: 是 | 付费: 否

答案:

答案useMemo(使用记忆化)缓存“计算结果”,useCallback(使用回调)缓存“函数引用”(可视作 useMemo(使用记忆化)的语法糖)。useCallback(使用回调)只有在子组件依赖引用相等性(referential equality)来跳过渲染(如 React.memo(React记忆化组件)或 shouldComponentUpdate(应更新组件))时才真正减少重渲染(re-render);否则只是额外开销。关键是:缓存函数引用 + 子组件按引用跳过更新,缺一不可。

1178. 当你在浏览器里输入并点击访问 google.com 时,背后会发生什么?请从网络到浏览器渲染流程说明。

  • 知识点: 前端 / 操作系统与网络 (主题: networking, web;标签: DNS, HTTP, Browser)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • 公司: Carsales
  • id: 69704548120fcc1591308fee | 官方: 是 | 付费: 否

答案:

答案可按链路回答:DNS(域名系统)解析 → 建立 TCP(传输控制协议)连接(三次握手)→ TLS(传输层安全)握手(HTTPS(安全超文本传输协议))→ 发送 HTTP(超文本传输协议)请求 → 服务端处理与返回 → 浏览器解析 HTML(超文本标记语言)构建 DOM(文档对象模型) → 解析 CSS(层叠样式表)构建 CSSOM(CSS对象模型) → 生成渲染树(render tree) → layout(布局)/paint(绘制)/composite(合成) → 执行 JS(JavaScript)(可能触发重排(reflow)/重绘(repaint))→ 资源(图片/JS/CSS)并行加载(受缓存、HTTP/2/3 影响)。
加分点:提到缓存(DNS/HTTP cache)、CDN(内容分发网络)、连接复用、QUIC/HTTP3、以及性能指标(TTFB(首字节时间)、LCP(最大内容绘制))。

1179. 需要通过在 searchData function(搜索数据函数)中写入 code(代码)来实现题目要求的三个 console(控制台)输出(现场题)。

  • 知识点: 前端 / 算法与数据结构 (主题: javascript;标签: recursion, dfs, search)
  • 类型: technical | 难度: hard | 子类型:
  • 分类: fullstack
  • id: 6970a2d4120fcc15913b16f9 | 官方: 是 | 付费: 否

答案:

答案题目通常要求在“嵌套/树形/数组+对象混合”的数据结构中按条件查找并输出指定格式。最稳的做法是递归(recursion) DFS(深度优先搜索):

  • 遍历当前层:如果是数组就遍历元素,如果是对象就遍历 key/value。
  • 当节点满足条件(如 id/name/type 匹配)时收集结果(先 push 到数组,避免边遍历边输出导致顺序不稳)。
  • 若存在子节点字段(如 children/items/sub),递归继续。
  • 遍历结束后,按题目要求的顺序统一 console.log 三段输出。
    加分点:用 Set(集合)记录 visited(已访问)防止重复/循环引用;把“匹配条件”和“输出格式”抽成参数,提升复用性。

1180. What are broadcast receivers? How is it implemented?

什么是广播接收器?它是如何实现的?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: coding
  • 分类: fullstack
  • id: 69b3792e58d557c902b98552 | 官方: 否 | 付费: 否

答案:

A broadcast receiver is a mechanism used for listening to system-level events like listening for incoming calls, SMS, etc. by the host application. It is implemented as a subclass of BroadcastReceiver class and each message is broadcasted as an intent object.

广播接收器是一种用于监听系统级事件(如来电、短信等)的机制,由宿主应用程序使用。它被实现为 BroadcastReceiver 类的子类,每条消息都作为意图对象进行广播。

public class MyReceiver extends BroadcastReceiver

public class MyReceiver extends BroadcastReceiver
{
public void onReceive(context,intent){}
public void onReceive(context,intent){}
}

1181. Explain in detail about the important file and folders used when you create a new Android application.

详细解释创建新 Android 应用程序时使用的重要文件和文件夹。
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b98555 | 官方: 否 | 付费: 否

答案:

App:

应用:

It describes the basic characteristics of the application and defines each of its components.

它描述了应用程序的基本特性,并定义了其每个组件。

java: - This contains the .java source files and .kt(source code written in Kotlin) source files of your project. By default, it includes a MainActivity.java or MainActivity.kt source file.

java:- 这包含项目的 .java 源文件和 .kt(用 Kotlin 编写的源代码)源文件。默认情况下,它包含一个 MainActivity.java 或 MainActivity.kt 源文件。
  • You create all the activities which have .java and .kt extensions under this file and also it includes all the code behind the application.
    res: - It is used to store the values for the resources that are used in various Android projects to include features of color, styles, dimensions, etc.

    res:- 它用于存储各种 Android 项目中使用的资源值,包括颜色、样式、尺寸等功能。
  • It is a directory for files like styles.xml, strings.xml, colors.xml, dimens.xml, etc.
    Scripts:

    脚本:

This is an auto-generated file that consists of compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion, applicationId, versionCode, and versionName. For example, build.gradle is a script file placed in the root project directory, defines build configurations that will be applied to all modules in your project.

这是一个自动生成的文件,包含 compileSdkVersion、buildToolsVersion、minSdkVersion、targetSdkVersion、applicationId、versionCode 和 versionName。例如,build.gradle 是一个位于项目根目录中的脚本文件,定义适用于项目中所有模块的构建配置。

1182. What is the difference between Serializable and Parcelable? Which is the best approach in Android?

Serializable 和 Parcelable 有什么区别?在 Android 中哪种方法最好?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b98558 | 官方: 否 | 付费: 否

答案:

While developing applications usually it needs to transfer data from one activity to another. This data needs to be added into a corresponding intent object. Some additional actions are required to make the data suitable for transfer. For doing that the object should be either serializable or parcelable.

在开发应用程序时,通常需要将数据从一个活动传输到另一个活动。这些数据需要添加到相应的意图对象中。需要一些额外的操作来使数据适合传输。为此,对象应该是可序列化的或可打包的。

Serializable: - Serializable is a standard Java interface. In this approach, you simply mark a class Serializable by implementing the interface and java will automatically serialize it.

Serializable:- Serializable 是标准的 Java 接口。在这种方法中,您只需通过实现接口将类标记为 Serializable,Java 将自动对其进行序列化。
  • Reflection is used during the process and many additional objects are created. This leads to plenty of garbage collection and poor performance.
    Parcelable: - Parcelable is an Android-specific interface. In this approach, you implement the serialization yourself.

    Parcelable: - Parcelable 是 Android 特有的接口。在这种方法中,你需要自行实现序列化。
  • Reflection is not used during this process and hence no garbage is created.
  • Parcelable is far more efficient than Serializable since it gets around some problems with the default Java serialization scheme. Also, it is faster because it is optimized for usage on the development of Android, and shows better results.

1183. What database is used in Android? How it is different from client-server database management systems?

Android 中使用的是什么数据库?它与客户端-服务器数据库管理系统有何不同?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b9855b | 官方: 否 | 付费: 否

答案:

SQLite is the open-source relational database used in Android. The SQLite engine is serverless, transactional, and also self-contained. Instead of the client-server relationship of most database management systems, the SQLite engine is integrally linked with the application. The library can be called dynamically and it can make use of simple function calls that reduce latency in database access.

SQLite 是 Android 中使用的开源关系数据库。SQLite 引擎是无服务器的、事务性的,并且也是自包含的。与大多数数据库管理系统的客户端-服务器关系不同,SQLite 引擎与应用程序紧密集成。该库可以动态调用,并可以利用简单的函数调用来减少数据库访问的延迟。

1184. What are the differences between Service and Thread?

Service 和 Thread 之间有什么区别?
  • 知识点: 前端 / 行为与软技能 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: behavioral | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b9855e | 官方: 否 | 付费: 否

答案:

The main difference between Service and Thread is given below:

Service 和 Thread 之间的主要区别如下:
ServiceThread
Service is an application component that facilitates an application to run in the background in order to perform long-running operations without user interaction.
Service 是一个应用程序组件,它促使应用程序在后台运行,以执行无需用户交互的长时操作。
A Thread is a concurrent unit of execution.
Thread 是一个并发的执行单元。
It exposes few functionalities to other applications by calling Context.bindService().
它通过调用 Context.bindService() 向其他应用程序暴露少量功能。
Google has brought in handlers and loopers into threads.
Google 已将 handlers 和 loopers 引入到线程中。
When an application is killed, service is not killed.
当应用程序被终止时,服务不会被终止。
When an application is killed, the thread is killed.
当应用程序被终止时,线程会被终止。

1185. What is the content provider? How it is implemented?

什么是内容提供者?它是如何实现的?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: coding
  • 分类: fullstack
  • id: 69b3792e58d557c902b98562 | 官方: 否 | 付费: 否

答案:

Content provider is one of the primary building blocks of Android applications, which manages access to a central repository of data. It acts as a standard interface that connects data in one process with code running in another process. So it can be used to share the data between different applications.

内容提供者是 Android 应用程序的主要构建块之一,它管理对中央数据存储库的访问。它充当一个标准接口,将一个进程中的数据与另一个进程中运行的代码连接起来。因此,它可以用于在不同应用程序之间共享数据。

They are responsible for encapsulating the data and providing mechanisms for defining data security. It is implemented as a subclass of ContentProviderclass and must implement a set of APIs that will enable other applications to perform transactions.

它们负责封装数据并提供定义数据安全的机制。它是作为 ContentProvider 类的子类实现的,并且必须实现一组 API,使其他应用程序能够执行事务。

public class MyContentprovider extends ContentProvider

public class MyContentprovider extends ContentProvider
{
public void onCreate(){}
public void onCreate(){}
}

1186. What is the significance of the .dex file?

.dex 文件的意义是什么?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b98596 | 官方: 否 | 付费: 否

答案:

Android programs are compiled into a .dex file (Dalvik Executable file) by DVM, which are then zipped into a .apk file on the device. .dex files are created by translating compiled applications written in java. .dex is a format that is optimized for effective storage and memory-mappable executions.

Android 程序由 DVM 编译成 .dex 文件(Dalvik 可执行文件),然后这些文件被压缩到设备上的 .apk 文件中。.dex 文件是通过翻译用 Java 编写的编译应用程序而创建的。.dex 是一种为有效存储和可内存映射执行而优化的格式。

1187. What is the difference between compileSdkVersion and targetSdkVersion?

compileSdkVersion 和 targetSdkVersion 之间有什么区别?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b98599 | 官方: 否 | 付费: 否

答案:

compileSdkVersion: - The compileSdkVersion is the version of API the application is compiled against. You can use Android API features involved in that version of the API (as well as all previous versions).

compileSdkVersion: - compileSdkVersion 是应用程序编译所针对的 API 版本。你可以使用该版本 API 中包含的 Android API 功能(以及所有先前版本)。
  • For example, if you try and use API 15 features but set compileSdkVersion to 14, you will get a compilation error. If you set compileSdkVersion to 15 you can still run the app on an API 14 device as long as your app’s execution paths do not attempt to invoke any APIs specific to API 15.
    targetSdkVersion: - The targetSdkVersion indicates that you have tested your app on (presumably up to and including) the version you specify. This is like a certification or sign-off you are giving the Android OS as a hint to how it should handle your application in terms of OS features.

    targetSdkVersion: - targetSdkVersion 表示你已在指定版本(可能包括该版本)上测试过你的应用。这就像你向 Android 操作系统发出的认证或签署,作为它应如何处理你的应用程序(在操作系统功能方面)的提示。
  • For example, setting the targetSdkVersion value to “11” or higher permits the system to apply a new default theme (Holo) to the application when running on Android 3.0 or higher. It also disables screen compatibility mode when running on larger screens (because support for API level 11 implicitly supports larger screens).

1188. Explain about java classes related to the use of sensors on Android.

解释有关在Android上使用传感器的Java类。
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b9859c | 官方: 否 | 付费: 否

答案:

Android sensor API provides many classes and interface for the use of sensors on Android. The important classes and interfaces of sensor API are given below: - Sensor class: This class helps you to create an instance of a specific sensor. It provides methods that let you determine a sensor’s capabilities.

Android传感器API提供了许多类和接口,用于在Android上使用传感器。传感器API的重要类和接口如下: - Sensor类:这个类帮助你创建特定传感器的实例。它提供了让你确定传感器能力的方法。
  • SensorManager class: This class is used to create an instance of the sensor service. It provides methods to access and list sensors, to register and unregister sensor listeners, etc.
  • SensorEvent class: This Java class is used to create a sensor event object. It provides information about the sensor event including raw sensor data, the accuracy of data, type of sensor, timestamp of event, etc.
  • SensorEventListener interface: This interface is used to create two callback methods that receive sensor event notifications when sensor value changes or when sensor accuracy changes. Those two methods are void onAccuracyChanged(Sensor sensor, int accuracy) which is called when sensor accuracy is changed andvoid onSensorChanged(SensorEvent event) which is called when sensor values are changed.

1189. What is JobScheduler?

什么是JobScheduler?
  • 知识点: 前端 (主题: android, mobile;标签: interviewbit, android, topic-specific, mobile)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b9859f | 官方: 否 | 付费: 否

答案:

The JobSchedular API is used for scheduling different types of jobs against the framework that will be executed in your app’s own process. This allows your application to perform the given task while being considerate of the device’s battery at the cost of timing control.

JobSchedular API用于针对框架调度不同类型的作业,这些作业将在你应用自己的进程中执行。这允许你的应用在考虑到设备电池的同时执行给定任务,但以牺牲时间控制为代价。

The JobScheduler supports batch scheduling of jobs. The Android system can combine jobs for reducing battery consumption. JobManager automatically handles the network unreliability so it makes handling uploads easier.

JobScheduler支持批量调度作业。Android系统可以合并作业以减少电池消耗。JobManager自动处理网络不可靠性,因此使处理上传更容易。

Here is some example of a situation where you would use this job scheduler: - Tasks that should be done when the device is connected to a power supply.

以下是一些你会使用此作业调度器的示例情况: - 当设备连接到电源时应执行的任务。
  • Tasks that require a Wi-Fi connection or network access.
  • Tasks should run on a regular basis as a batch where the timing is not critical.
    Conclusion

    结论

Android system gives a platform for a developer from which they can display the applications to smartphone users and find potential customers out of them. It also provides paid and free applications for the users that could secure their data serves as a platform for information and gives various services as per the needs of the customers.

Android系统为开发者提供了一个平台,他们可以通过该平台向智能手机用户展示应用程序,并从中找到潜在客户。它也为用户提供付费和免费应用程序,这些应用程序可以保护用户数据,作为一个信息平台,并根据客户需求提供各种服务。

Useful Resources:

有用资源:
  • Android Developer Salary
  • Android Projects
  • Android MCQ
  • Android Developer Resume
  • Android Developer Skills
  • Android Frameworks
  • Mobile Testing
  • iOS Developer

1190. What are property decorators?

什么是属性装饰器?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b985f5 | 官方: 否 | 付费: 否

答案:

These are the second most popular types of decorators. They enable us to enhance some of the properties in our classes. We can certainly understand why we utilize any certain class property by using a property decorator.

这些是第二流行的装饰器类型。它们使我们能够增强类中的某些属性。通过使用属性装饰器,我们当然可以理解为什么利用某个特定的类属性。

There are many property decorators available for example @Input(), @Output, @ReadOnly(), @Override()

有许多可用的属性装饰器,例如 @Input()、@Output、@ReadOnly()、@Override()

Example:

示例:

import { Component, Input } from '@angular/core';

import { Component, Input } from '@angular/core';
@Component({
@Component({
selector: 'prop-component',
selector: 'prop-component',
template: '
This is a test component !
'
template: '
这是一个测试组件!
'
})
export class PropComponent {
导出类 PropComponent {
@Input()
@Input()
exampleProperty: string;
exampleProperty: string;
}
The input binding would be sent via a component property binding:
输入绑定将通过组件属性绑定发送:

<prop-component

<prop-component
[propProperty]="propData">
[propProperty]="propData">

1191. Angular by default, uses client-side rendering for its applications.

Angular 默认对其应用程序使用客户端渲染。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792e58d557c902b985f8 | 官方: 否 | 付费: 否

答案:

Can one make an angular application to render on the server-side?

能否让 Angular 应用程序在服务器端进行渲染?

Yes, angular provides a technology called Angular Universal , which can be used to render applications on the server-side.

可以,Angular 提供了一种名为 Angular Universal 的技术,可用于在服务器端渲染应用程序。

The advantages of using Angular Universal are: - First time users can instantly see a view of the application. This benefits in providing better user experience.

使用 Angular Universal 的优势包括:- 首次用户能立即看到应用程序的视图。这有助于提供更好的用户体验。
  • Many search engines expect pages in plain HTML, thus, Universal can make sure that your content is available on every search engine, which leads to better SEO.
  • Any server-side rendered application loads faster since rendered pages are available to the browser sooner.

1192. What is Eager and Lazy loading?

什么是急切加载和懒加载?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b985fc | 官方: 否 | 付费: 否

答案:

  • Loading: The eager loading technique is the default module-loading strategy. Eager loading feature modules are loaded before the program begins. This is primarily utilized for small-scale applications.
  • Lazy Loading: Lazy loading loads the feature modules dynamically as needed. This speeds up the application. It is utilized for larger projects where all of the modules are not required at the start.

1193. What is view encapsulation in Angular?

在 Angular 中什么是视图封装?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b985ff | 官方: 否 | 付费: 否

答案:

View encapsulation specifies if the component's template and styles can impact the entire program or vice versa.

视图封装指定组件的模板和样式是否会影响整个程序,反之亦然。

Angular offers three encapsulation methods: - Native: The component does not inherit styles from the main HTML. Styles defined in this component's @Component decorator are only applicable to this component.

Angular 提供了三种封装方法:- Native:该组件不会继承主 HTML 的样式。此组件的 @Component 装饰器中定义的样式仅适用于该组件。
  • Emulated (Default): The component inherits styles from the main HTML. Styles set in the @Component decorator are only applicable to this component.
  • None: The component's styles are propagated back to the main HTML and therefore accessible to all components on the page. Be wary of programs that have None and Native components. Styles will be repeated in all components with Native encapsulation if they have No encapsulation.

1194. What are RxJs in Angular ?

Angular 中的 RxJs 是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98602 | 官方: 否 | 付费: 否

答案:

RxJS is an acronym that stands for Reactive Extensions for JavaScript. It is used to enable the use of observables in our JavaScript project, allowing us to do reactive programming. RxJS is utilized in many popular frameworks, including Angular since it allows us to compose our asynchronous or callback-based code into a sequence of operations executed on a data stream that releases values from a publisher to a subscriber. Other programming languages, such as Java and Python, offer packages that allow them to develop reactive programs utilizing observables.

RxJS 是 Reactive Extensions for JavaScript 的缩写。它用于在我们的 JavaScript 项目中启用可观察对象的使用,使我们可以进行响应式编程。RxJS 被许多流行的框架所使用,包括 Angular,因为它允许我们将异步或基于回调的代码组合成一系列在数据流上执行的操作,该数据流将值从发布者释放给订阅者。其他编程语言,如 Java 和 Python,也提供了允许它们利用可观察对象开发响应式程序的包。

Most of the time, rxJs is used in HTTP calls with angular. Because http streams are asynchronous data, we can subscribe to them and apply filters to them.

大多数情况下,RxJS 在 Angular 中用于 HTTP 调用。因为 HTTP 流是异步数据,我们可以订阅它们并对其应用过滤器。

Example: The following is a simple example of how RxJs can be utilized with HTTP calls.

示例:以下是一个简单的示例,展示了如何将 RxJs 与 HTTP 调用结合使用。

let  stream1 = httpc.get("https://www.example.com/somedata");

let stream1 = httpc.get("https://www.example.com/somedata");
let stream2 = stream1.pipe(filter(x=>x>3));
let stream2 = stream1.pipe(filter(x=>x>3));
stream2.subscribe(res=>this.Success(res),res=>this.Error(res));
stream2.subscribe(res=>this.Success(res),res=>this.Error(res));

1195. Explain string interpolation and property binding in Angular.

解释 Angular 中的字符串插值和属性绑定。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98605 | 官方: 否 | 付费: 否

答案:

  • String interpolation and property binding are parts of data-binding in Angular.
  • Data-binding is a feature in angular, which provides a way to communicate between the component(Model) and its view(HTML template).
  • Data-binding can be done in two ways, one-way binding and two-way binding.
  • In Angular, data from the component can be inserted inside the HTML template. In one-way binding, any changes in the component will directly reflect inside the HTML template but, vice-versa is not possible. Whereas, it is possible in two-way binding.
  • String interpolation and property binding allow only one-way data binding.
  • String interpolation uses the double curly braces {} to display data from the component. Angular automatically runs the expression written inside the curly braces, for example, {{ 2 + 2 }} will be evaluated by Angular and the output 4, will be displayed inside the HTML template. Using property binding, we can bind the DOM properties of an HTML element to a component's property. Property binding uses the square brackets [ ] syntax.

1196. How are observables different from promises?

可观察对象与 Promise 有何不同?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98608 | 官方: 否 | 付费: 否

答案:

The first difference is that an Observable is lazy whereas a Promise is eager .

第一个区别是 Observable 是惰性的,而 Promise 是急切的。
PromiseObservable
Emits a single value
发出单个值
Emits multiple values over a period of time
在一段时间内发出多个值
Not Lazy
非惰性
Lazy. An observable is not called until we subscribe to the observable
惰性。直到我们订阅 Observable 才会被调用
Cannot be cancelled
无法取消
Can be cancelled by using the unsubscribe() method
可以通过使用 unsubscribe() 方法取消
Observable provides operators like map, forEach, filter, reduce, retry, retryWhen etc.
Observable 提供了操作符,如 map、forEach、filter、reduce、retry、retryWhen 等。

Consider the following Observable:

考虑以下 Observable:

const observable = rxjs.Observable.create(observer => {

const observable = rxjs.Observable.create(observer => {
console.log('Text inside an observable');
console.log('Text inside an observable');
observer.next('Hello world!');
observer.next('Hello world!');
observer.complete();
observer.complete();
});
console.log('Before subscribing an Observable');
console.log('在订阅一个Observable之前');
observable.subscribe((message)=> console.log(message));
observable.subscribe((message)=> console.log(message));
When you run the above Observable, you can see messages being displayed in the following order:
当你运行上述Observable时,可以看到消息按以下顺序显示:

Before subscribing an Observable

在订阅一个Observable之前
Text inside an observable
observable内部文本
Hello world!
你好,世界!
As you can see, observables are lazy. Observable runs only when someone subscribes to them hence, the message “Before subscribing…” is displayed ahead of the message inside the observable.
如你所见,observable是惰性的。Observable只有在有人订阅它们时才会运行,因此,“在订阅…”消息会显示在observable内部的消息之前。

Now let’s consider a Promise:

现在让我们考虑一个Promise:

const promise = new Promise((resolve, reject) => {

const promise = new Promise((resolve, reject) => {
console.log('Text inside promise');
console.log('promise内部文本');
resolve('Hello world!');
resolve('你好,世界!');
});
console.log('Before calling then method on Promise');
console.log('在Promise上调用then方法之前');
greetingPoster.then(message => console.log(message));
greetingPoster.then(message => console.log(message));
Running the above promise, the messages will be displayed in the following order:
运行上述promise,消息将按以下顺序显示:

Text inside promise

promise内部文本
Before calling then method on Promise
在 Promise 上调用 then 方法之前
Hello world!
你好,世界!
As you can see the message inside Promise is displayed first. This means that a promise runs before the then method is called. Therefore, promises are eager .
如您所见,Promise 内部的消息会首先显示。这意味着 Promise 在 then 方法被调用之前就已经运行。因此,Promise 是急切的。

The next difference is that Promises are always asynchronous . Even when the promise is immediately resolved. Whereas an Observable, can be both synchronous and asynchronous .

另一个区别是 Promise 总是异步的。即使 Promise 立即被解决也是如此。然而,Observable 可以同时是同步的和异步的。

The above example of an observable is the case to show that an observable is synchronous. Let’s see the case where an observable can be asynchronous:

上面关于 observable 的例子是展示 observable 是同步的情况。让我们看看 observable 可以是异步的情况:

const observable = rxjs.Observable.create(observer => {

const observable = rxjs.Observable.create(observer => {
setTimeout(()=>{
setTimeout(()=>{
observer.next('Hello world');
observer.next('Hello world');
observer.complete();
observer.complete();
},3000)
});
console.log('Before calling subscribe on an Observable');
console.log('在 Observable 上调用 subscribe 之前');
observable.subscribe((data)=> console.log(data));
observable.subscribe((data)=> console.log(data));
console.log('After calling subscribe on an Observable');
console.log('在 Observable 上调用 subscribe 之后');
The messages will be displayed in the following order:
消息将按以下顺序显示:

Before calling subscribe on an Observable

在 Observable 上调用 subscribe 之前
After calling subscribe on an Observable
在 Observable 上调用 subscribe 之后
Hello world!
你好,世界!
You can see in this case, observable runs asynchronously.
你可以看到在这种情况下,observable 是异步运行的。

The next difference is that Observables can emit multiple values whereas Promises can emit only one value.

下一个区别是 Observable 可以发出多个值,而 Promise 只能发出一个值。

The biggest feature of using observables is the use of operators . We can use multiple operators on an observable whereas, there is no such feature in a promise.

使用 Observables 最大的特点是使用操作符。我们可以对 observable 使用多个操作符,而 Promise 没有这样的功能。

1197. Explain the concept of Dependency Injection?

解释一下依赖注入的概念?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9860b | 官方: 否 | 付费: 否

答案:

Dependency injection is an application design pattern which is implemented by Angular.

依赖注入是一种应用设计模式,由 Angular 实现。

It also forms one of the core concepts of Angular.

它也构成了 Angular 的核心概念之一。

So what is dependency injection in simple terms?

那么,简单来说依赖注入是什么?

Let’s break it down, dependencies in angular are nothing but services which have functionality. The functionality of a service, can be needed by various components and directives in an application. Angular provides a smooth mechanism by which we can inject these dependencies into our components and directives.

让我们分解一下,Angular 中的依赖就是具有功能的服务。服务的功能可以被应用中的各种组件和指令所需要。Angular 提供了一种流畅的机制,我们可以通过它将这些依赖注入到组件和指令中。

So basically, we are just making dependencies which are injectable across all components of an application.

所以基本上,我们只是让依赖在应用的所有组件中可被注入。

Let’s understand how DI (Dependency Injection) works:

让我们了解 DI(依赖注入)是如何工作的:

Consider the following service, which can be generated using: ng g service test

考虑以下服务,可以使用以下命令生成:ng g service test

import { Injectable } from '@angular/core';

import { Injectable } from '@angular/core';
@Injectable({
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class TestService {
export class TestService {
importantValue:number = 42;
importantValue:number = 42;
constructor()
constructor()
returnImportantValue(){
returnImportantValue(){
return this.importantValue;
return this.importantValue;
}
}
As one can notice, we can create injectable dependencies by adding the @Injectable decorator to a class.
正如大家所注意到的,我们可以通过给类添加 @Injectable 装饰器来创建可注入的依赖。

We inject the above dependency inside the following component:

我们在以下组件中注入上述依赖:

import { TestService } from './../test.service';

import { TestService } from './../test.service';
import { Component, OnInit } from '@angular/core';
import { Component, OnInit } from '@angular/core';

@Component({

@Component({
selector: 'app-test',
selector: 'app-test',
templateUrl: './test.component.html',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
export class TestComponent implements OnInit {
value:number;
value:number;
constructor(private testService:TestService)
constructor(private testService:TestService)

ngOnInit() {

ngOnInit() {
this.value = this.testService.returnImportantValue();
this.value = this.testService.returnImportantValue();
}
}
One can see we have imported our TestService at the top of the page. Then, we created an instance inside the constructor of the component and implemented the returnImportantValue function of the service.
我们可以看到,在页面顶部导入了我们的 TestService。然后,在组件的构造函数内部创建了一个实例,并实现了该服务的 returnImportantValue 函数。

From the above example, we can observe how angular provides a smooth way to inject dependencies in any component.

从上述示例中,我们可以观察到 Angular 如何在任何组件中提供一种顺畅的依赖注入方式。

1198. What are pipes in Angular explain with an example?

Angular 中的管道是什么?请举例说明。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98613 | 官方: 否 | 付费: 否

答案:

Pipes are functions that simplify the process of wiring up your JavaScript expressions and transforming them into their desired output. They can be compared to, say, string functions in other programming languages. Pipes also allow you to combine multiple expressions together, whether they're all values or some values and some declarations.

管道是简化将 JavaScript 表达式连接起来并转换为所需输出的过程的函数。它们可以与其他编程语言中的字符串函数相类比。管道还允许你将多个表达式组合在一起,无论是全为值还是某些值和某些声明。

For example:

例如:

var css = myTheme.color | "red" ;

var css = myTheme.color | "red" ;
This line would assign a value to css , and it's equivalent to writing out the following code:
这一行会为 css 赋值,并且它等同于编写以下代码:

Pipes have several built-in functions that allow you to transform data, such as value and extract. We can also create our own custom pipes.

管道有几个内置函数,允许你转换数据,例如 value 和 extract。我们也可以创建自己的自定义管道。

Pipes are data transformers that execute on an Angular Component's output. They take in data and return transformed data. For example, if you have an expression such as number | 1000, the number pipe will take data from the output and transform it into 1000. In Angular, there are many built-in pipes that you can use. You can also create your own custom pipes by implementing the PipeTransform interface in a class.

管道是在 Angular 组件的输出上执行的数据转换器。它们接收数据并返回转换后的数据。例如,如果你有一个表达式如 number | 1000,数字管道将从输出中获取数据并将其转换为 1000。在 Angular 中,有许多你可以使用的内置管道。你也可以通过在一个类中实现 PipeTransform 接口来创建自己的自定义管道。

Pipes receive an input which can be a value expression, a function returning an expression, or even a component property., that outputs a number with a value of 1,000. With a pipe, you can transform this output into a formatted string of "1,000" or "1.000".

管道接收输入,该输入可以是值表达式、返回表达式的函数,甚至是组件属性,它输出一个值为 1,000 的数字。使用管道,你可以将此输出转换为格式化的字符串 "1,000" 或 "1.000"。

Example:

示例:

import { Component } from '@angular/core';

import { Component } from '@angular/core';

@Component({

@Component({
selector: 'app-root',
selector: 'app-root',
template: {{ title | uppercase}},
template: {{ title | uppercase}},
styleUrls: ['./app.component.css']
styleUrls: ['./app.component.css']
})
export class AppComponent {
export class AppComponent {
title = 'this is an example of custom pies in angular';
title = 'this is an example of custom pies in angular';
}
Output:
输出:

THIS IS AN EXAMPLE OF CUSTOM PIPES IN ANGULAR

这是Angular中自定义管道的示例

1199. What exactly is a parameterized pipe?

参数化管道究竟是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98617 | 官方: 否 | 付费: 否

答案:

To fine-tune its output, a pipe can receive any number of optional parameters. The parameterized pipe is constructed by first stating the pipe name followed by a colon (:) and then the parameter value. If the pipe supports several arguments, use colons to separate the values.

为了微调其输出,管道可以接收任意数量的可选参数。参数化管道通过先写出管道名,后跟冒号(:),再写参数值来构造。如果管道支持多个参数,使用冒号分隔值。

Example: Let's look at a birthday with a certain format (dd/MM/yyyy):

示例:让我们看一个具有特定格式(dd/MM/yyyy)的生日的例子:

import { Component } from '@angular/core';

import { Component } from '@angular/core';
@Component({
@Component({
selector: 'app-example',
selector: 'app-example',
template: <p>Birthday is {{ birthday | date:'dd/MM/yyyy'}}</p>
template: <p>Birthday is {{ birthday | date:'dd/MM/yyyy'}}</p>
})
export class ExampleComponent {
export class ExampleComponent {
birthday = new Date(2000, 7, 15);
birthday = new Date(2000, 7, 15);
}

1200. What are class decorators?

什么是类装饰器?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9861a | 官方: 否 | 付费: 否

答案:

Class Decorators are the highest-level decorators that determine the purpose of the classes. They indicate to Angular that a specific class is a component or module. And the decorator enables us to declare this effect without having to write any code within the class.

类装饰器是最高级别的装饰器,它们决定了类的用途。它们向Angular表明特定类是组件或模块。装饰器使我们能够在不编写类内任何代码的情况下声明这种效果。

Example:

示例:

import { NgModule, Component } from '@angular/core';

import { NgModule, Component } from '@angular/core';
@Component({
@Component({
selector: 'class-component',
selector: 'class-component',
template: '
This is a class component !
',
template: '
This is a class component !
',
})
export class ClassComponent {
export class ClassComponent {
constructor() {
constructor() {
console.log('This is a class component!');
console.log('This is a class component!');
}
}
@NgModule({
@NgModule({
imports: [],
imports: [],
declarations: [],
declarations: [],
})
export class ClassModule {
export class ClassModule {
constructor() {
constructor() {
console.log('This is a class module!');
console.log('This is a class module!');
}
}
It is a component or module in which no code in the class is required to tell Angular. We only need to design it, and Angular will take care of the rest.
这是一种组件或模块,其中类中没有任何代码需要告诉 Angular。我们只需设计它,Angular 会处理其余部分。

1201. What are Method decorators?

什么是方法装饰器?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9861d | 官方: 否 | 付费: 否

答案:

Method decorators, as the name implies, are used to add functionality to the methods defined within our class.

方法装饰器,顾名思义,用于向类中定义的方法添加功能。

Example: @HostListener, is a good example of method decorators.

示例:@HostListener,是方法装饰器的一个很好的例子。

import { Component, HostListener } from '@angular/core';

import { Component, HostListener } from '@angular/core';
@Component({
@Component({
selector: 'method-component',
selector: 'method-component',
template: '
This is a test method component !
',
template: '
这是一个测试方法组件!
',
})
export class MethodComponent {
export class MethodComponent {
@HostListener('click', ['$event'])
@HostListener('click', ['$event'])
onHostClick(event: Event) {
onHostClick(event: Event) {
console.log('clicked now this event is available !');
console.log('clicked now this event is available !');
}
}
The @HostListener decorator is used before the onHostClick () method in the above example code.
在上述示例代码中,@HostListener 装饰器被用在 onHostClick() 方法之前。

1202. Explain MVVM architecture

解释 MVVM 架构
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: system-design
  • 分类: fullstack
  • id: 69b3792f58d557c902b98622 | 官方: 否 | 付费: 否

答案:

MVVM architecture consists of three parts:

MVVM 架构由三部分组成:
  1. Model 2. View 3. ViewModel

    1. 模型 2. 视图 3. 视图模型
  • Model contains the structure of an entity. In simple terms it contains data of an object.
  • View is the visual layer of the application. It displays the data contained inside the Model. In angular terms, this will be the HTML template of a component.
  • ViewModel is an abstract layer of the application. A viewmodel handles the logic of the application. It manages the data of a model and displays it in the view.

View and ViewModel are connected with data-binding (two-way data-binding in this case). Any change in the view, the viewmodel takes a note and changes the appropriate data inside the model.

视图和视图模型通过数据绑定(在这种情况下是双向数据绑定)连接。视图中的任何变化,视图模型会记录下来并更改模型中相应的数据。

1203. What is the Component Decorator in Angular?

Angular 中的组件装饰器是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98627 | 官方: 否 | 付费: 否

答案:

TypeScript classes are used to create components. This class genre is then decorated with the "@Component" decorator. The decorator's function is to take a metadata object holding component information and decorate it.

TypeScript 类被用来创建组件。这个类类型随后会被 "@Component" 装饰器装饰。该装饰器的功能是获取一个包含组件信息的元数据对象并进行装饰。

A Decorator is always preceded by @. The Decorator must come before the class definition. We can also make our own decorators.

装饰器总是以 @ 开头。装饰器必须放在类定义之前。我们也可以创建自己的装饰器。

Example: The example below shows us a Class decorated with the @Component decorator.

示例:下面的示例展示了一个用 @Component 装饰器装饰的类。

import {Component} from '@angular/core';

import {Component} from '@angular/core';

@Component({

@Component({
selector: 'app-root',
selector: 'app-root',
templateUrl: './app.component.html',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
styleUrls: ['./app.component.css']
})
export class AppComponent {
export class AppComponent {
title = 'Example component';
title = '组件示例';
}
The metadata object received by the decorator has values such as templateUrl, selector, and others, with the templateUrL property pointing to an HTML file that defines what you see on the application.
装饰器接收的元数据对象包含诸如templateUrl、selector等值,其中templateUrl属性指向一个HTML文件,该文件定义了你在应用程序中看到的内容。

1204. What are lifecycle hooks in Angular? Explain a few lifecycle hooks.

什么是Angular中的生命周期钩子?请解释几个生命周期钩子。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9862a | 官方: 否 | 付费: 否

答案:

Every component in Angular has a lifecycle, and different phases it goes through from the time of creation to the time it's destroyed. Angular provides hooks to tap into these phases and trigger changes at specific phases in a lifecycle.

Angular中的每个组件都有其生命周期,从创建到销毁时会经历不同阶段。Angular提供了钩子来介入这些阶段,并在生命周期的特定阶段触发更改。
  • ngOnChanges( ) This hook/method is called before ngOnInit and whenever one or more input properties of the component change.This method/hook receives a SimpleChanges object which contains the previous and current values of the property.
  • ngOnInit( ) This hook gets called once, after the ngOnChanges hook.It initializes the component and sets the input properties of the component.
  • ngDoCheck( ) It gets called after ngOnChanges and ngOnInit and is used to detect and act on changes that cannot be detected by Angular.We can implement our change detection algorithm in this hook. ngAfterContentInit( ) It gets called after the first ngDoCheck hook. This hook responds after the content gets projected inside the component.
  • ngAfterContentChecked( ) It gets called after ngAfterContentInit and every subsequent ngDoCheck. It responds after the projected content is checked.
  • ngAfterViewInit( ) It responds after a component's view, or a child component's view is initialized.
  • ngAfterViewChecked( ) It gets called after ngAfterViewInit, and it responds after the component's view, or the child component's view is checked.
  • ngOnDestroy( ) It gets called just before Angular destroys the component. This hook can be used to clean up the code and detach event handlers.

Let’s understand how to use ngOnInit hook, since it’s the most often used hook. If one has to process a lot of data during component creation, it’s better to do it inside ngOnInit hook rather than the constructor:

让我们了解如何使用ngOnInit钩子,因为它是最常用的钩子。如果需要在组件创建时处理大量数据,最好在ngOnInit钩子中完成,而不是在构造函数中:
import { Component, OnInit } from '@angular/core';
import { Component, OnInit } from '@angular/core';

@Component({

@Component({
selector: 'app-test',
selector: 'app-test',
templateUrl: './test.component.html',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
export class TestComponent implements OnInit {
constructor()
constructor()

ngOnInit() {

ngOnInit() {
this.processData();
this.processData();
}

processData(){

processData(){
// Do something..
// 做点什么..
}

}
As you can see we have imported OnInit but we have used ngOnInit function. This principle should be used with the rest of the hooks as well.

如你所见,我们导入了OnInit,但使用了ngOnInit函数。这个原则也应适用于其余的生命周期钩子。

1205. What are router links?

什么是路由器链接?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9862d | 官方: 否 | 付费: 否

答案:

RouterLink is an anchor tag directive that gives the router authority over those elements. Because the navigation routes are set.

RouterLink是一个锚点标签指令,它赋予路由器对这些元素的控制权。因为导航路由已经设置好了。

Example: As seen below, you may pass string values to the router-link directive.

示例:如下所示,你可以向router-link指令传递字符串值。

Example of an Angular Router

Example of an Angular Router



1206. What exactly is the router state?

路由器状态到底是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98630 | 官方: 否 | 付费: 否

答案:

RouterState is a route tree. This tree's nodes are aware of the "consumed" URL segments, retrieved arguments, and processed data. You may use the Router service and the routerState property to get the current RouterState from anywhere in the application.

RouterState是一个路由树。这棵树的节点知道“已消费”的URL段、检索到的参数以及处理过的数据。你可以使用Router服务和routerState属性,从应用程序中的任何位置获取当前的RouterState。

Example:

示例:

@Component({templateUrl:'example.html'})

@Component({templateUrl:'example.html'})
class MyComponent {
class MyComponent {
constructor(router: Router) {
constructor(router: Router) {
const state: RouterState = router.routerState;
const state: RouterState = router.routerState;
const root: ActivatedRoute = state.root;
const root: ActivatedRoute = state.root;
const child = root.firstChild;
const child = root.firstChild;
const id: Observable = child.params.map(p => p.id);
const id: Observable = child.params.map(p => p.id);
//...
}
}

1207. What does Angular Material means?

Angular Material是什么意思?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98633 | 官方: 否 | 付费: 否

答案:

Angular Material is a user interface component package that enables professionals to create a uniform, appealing, and fully functioning websites, web pages, and web apps. It does this by adhering to contemporary web design concepts such as gentle degradation and browser probability.

Angular Material是一个用户界面组件包,它使专业人员能够创建统一、美观且功能齐全的网站、网页和网络应用程序。它通过遵循当代网页设计概念(如优雅降级和浏览器兼容性)来实现这一点。

1208. What is ngOnInit?

什么是ngOnInit?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98636 | 官方: 否 | 付费: 否

答案:

ngOnInit is a lifecycle hook and callback function used by Angular to mark the creation of a component. It accepts no arguments and returns a void type.

ngOnInit是一个生命周期钩子和回调函数,Angular用它来标记组件的创建。它不接受任何参数,并返回void类型。

Example:

示例:

export class MyComponent implements OnInit {

export class MyComponent implements OnInit {
constructor()
constructor()
ngOnInit(): void {
ngOnInit(): void {
//....
}
}

1209. What is transpiling in Angular ?

Angular中的转译是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98639 | 官方: 否 | 付费: 否

答案:

Transpiling is the process of transforming the source code of one programming language into the source code of another. Typically, in Angular, this implies translating TypeScript to JavaScript. TypeScript (or another language like as Dart) can be used to develop code for your Angular application, which is subsequently transpiled to JavaScript. This occurs naturally and internally.

转译是将一种编程语言的源代码转换为另一种编程语言源代码的过程。通常,在Angular中,这意味着将TypeScript转换为JavaScript。您可以使用TypeScript(或其他语言,如Dart)为Angular应用程序编写代码,这些代码随后被转译为JavaScript。这一过程会自然而然地内部发生。

1210. What are HTTP interceptors ?

什么是HTTP拦截器?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9863c | 官方: 否 | 付费: 否

答案:

Using the HttpClient, interceptors allow us to intercept incoming and outgoing HTTP requests. They are capable of handling both HttpRequest and HttpResponse. We can edit or update the value of the request by intercepting the HTTP request, and we can perform some specified actions on a specific status code or message by intercepting the answer.

使用HttpClient时,拦截器允许我们拦截传入和传出的HTTP请求。它们能够处理HttpRequest和HttpResponse。我们可以通过拦截HTTP请求来编辑或更新请求的值,并且可以通过拦截响应来对特定的状态码或消息执行某些指定操作。

Example: In the following example we will set the Authorization header Bearer for all the requests:

示例:在以下示例中,我们将为所有请求设置Authorization头部的Bearer:

token.interceptor.ts

token.interceptor.ts
import { Injectable } from '@angular/core';
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs/Observable';

@Injectable()

@Injectable()
export class TokenInterceptor implements HttpInterceptor {
export class TokenInterceptor implements HttpInterceptor {
public intercept(req: HttpRequest, next: HttpHandler): Observable<HttpEvent> {
public intercept(req: HttpRequest, next: HttpHandler): Observable<HttpEvent> {
const token = localStorage.getItem('token') as string;
const token = localStorage.getItem('token') as string;
if (token) {
if (token) {
req = req.clone({
req = req.clone({
setHeaders: {
setHeaders: {
'Authorization': Bearer ${token}
'Authorization': Bearer ${token}
}
});
}
return next.handle(req);
return next.handle(req);
}
}
We have to register the interceptor as singleton in the module providers
我们必须在模块提供者中将拦截器注册为单例

app.module.ts

app.module.ts
import { NgModule } from '@angular/core';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserModule } from '@angular/platform-browser';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppComponent } from './app.component';
import { AppComponent } from './app.component';
import { TokenInterceptor } from './token.interceptor';
import { TokenInterceptor } from './token.interceptor';

@NgModule({

@NgModule({
imports: [
imports: [
BrowserModule
BrowserModule
],
declarations: [
declarations: [
AppComponent
AppComponent
],
bootstrap: [AppComponent],
bootstrap: [AppComponent],
providers: [{
providers: [{
provide: HTTP_INTERCEPTORS,
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
useClass: TokenInterceptor,
multi: true
multi: true
}]
})
export class AppModule {}
export class AppModule {}

1211. What is AOT compilation? What are the advantages of AOT?

什么是AOT编译?AOT编译有哪些优点?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b9863f | 官方: 否 | 付费: 否

答案:

Every Angular application consists of components and templates that the browser cannot understand. Therefore, all the Angular applications need to be compiled first before running inside the browser.

每个Angular应用都由浏览器无法理解的组件和模板组成。因此,所有Angular应用在浏览器中运行前都需要先进行编译。

Angular provides two types of compilation: - JIT(Just-in-Time) compilation

Angular提供了两种编译类型:- JIT(即时)编译
  • AOT(Ahead-of-Time) compilation

In JIT compilation, the application compiles inside the browser during runtime. Whereas in the AOT compilation, the application compiles during the build time.

在JIT编译中,应用在浏览器内运行时进行编译。而在AOT编译中,应用在构建时进行编译。

The advantages of using AOT compilation are: - Since the application compiles before running inside the browser, the browser loads the executable code and renders the application immediately, which leads to faster rendering.

使用AOT编译的优点有:- 由于应用在浏览器中运行前已完成编译,浏览器加载可执行代码并立即渲染应用,从而实现更快的渲染。
  • In AOT compilation, the compiler sends the external HTML and CSS files along with the application, eliminating separate AJAX requests for those source files, which leads to fewer ajax requests.
  • Developers can detect and handle errors during the building phase, which helps in minimizing errors.
  • The AOT compiler adds HTML and templates into the JS files before they run inside the browser. Due to this, there are no extra HTML files to be read, which provide better security to the application.
    By default, angular builds and serves the application using JIT compiler:

    默认情况下,Angular使用JIT编译器构建和服务应用:

ng build

ng build
ng serve
ng serve
For using AOT compiler following changes should be made:
要使用AOT编译器,应进行以下更改:

ng build --aot

ng build --aot
ng serve --aot
ng serve --aot

1212. What is Change Detection, and how does the Change Detection Mechanism work?

什么是变更检测,变更检测机制是如何工作的?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98642 | 官方: 否 | 付费: 否

答案:

The process of synchronizing a model with a view is known as Change Detection. Even when utilizing the ng Model to implement two-way binding, which is syntactic sugar on top of a unidirectional flow. Change detection is incredibly fast, but as an app's complexity and the number of components increase, change detection will have to do more and more work.

将模型与视图同步的过程称为变更检测。即使利用ng Model实现双向绑定(这只是在单向流之上的语法糖),变更检测的速度也非常快,但随着应用复杂度和组件数量的增加,变更检测需要做的工作也越来越多。

Change Detection Mechanism-moves only ahead and never backward, beginning with the root component and ending with the last component. This is what one-way data flow entails. The tree of components is the architecture of an Angular application. Each component is a child, but the child is not a parent. A $digest loop is no longer required with the one-way flow.

变更检测机制-从根组件开始,到最后一个组件结束,只向前移动,从不向后。这就是单向数据流的含义。组件树是Angular应用的架构。每个组件都是子组件,但子组件不是父组件。使用单向流后,不再需要$digest循环。

1213. What is a bootstrapping module?

什么是引导模块?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular, topic-specific, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b98645 | 官方: 否 | 付费: 否

答案:

Every application contains at least one Angular module, which is referred to as the bootstrapping module. AppModule is the most popular name for it.

每个应用程序都至少包含一个Angular模块,这个模块被称为引导模块。AppModule是它最常见的名称。

Example: The following is the default structure of an AngularCLI-generated AppModule:

示例:以下是AngularCLI生成的AppModule的默认结构:

import { BrowserModule } from '@angular/platform-browser';

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';

import { AppComponent } from './app.component';

import { AppComponent } from './app.component';

@NgModule({

@NgModule({
declarations: [
declarations: [
AppComponent
AppComponent
],
imports: [
imports: [
BrowserModule,
BrowserModule,
FormsModule,
FormsModule,
HttpClientModule
HttpClientModule
],
providers: [],
providers: [],
bootstrap: [AppComponent]
bootstrap: [AppComponent]
})
export class AppModule
export class AppModule

1214. Explain Lazy Loading in Angular with appropriate syntax.

解释 Angular 中的懒加载,并给出适当的语法。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986b3 | 官方: 否 | 付费: 否

答案:

Lazy loading is a feature of Angular which helps in bringing down the size of large files. This is accomplished by lazily loading the files that are to be used again and again.

懒加载是 Angular 的一项功能,有助于减小大型文件的大小。这是通过懒加载那些需要反复使用的文件来实现的。

Angular 8 provides support for dynamic imports in our router configuration. In other words, we use the import statement for lazy loading of the module and this will be understood by the webpack, IDEs (Integrated Development Environments), etc.

Angular 8 在我们的路由器配置中提供了对动态导入的支持。换句话说,我们使用导入语句进行模块的懒加载,这将被 webpack、IDE(集成开发环境)等理解。

Syntax

语法

{path: 'user', loadChildren: () =>

{path: 'user', loadChildren: () =>
import('./users/user.module').then(my => my.UserModule)};
import('./users/user.module').then(my => my.UserModule)};
Explanation
解释

In the above code snippet, the loadChildren expects a function that uses the dynamic import syntax to import the lazy loaded module only when it is needed. As is evident from the above code snippet, the dynamic import is based on promises and gives us access to the module, where the module’s class can be called.

在上述代码片段中,loadChildren 期望一个函数,该函数使用动态导入语法,仅在需要时才导入懒加载的模块。从上述代码片段可以看出,动态导入基于 Promise,并让我们访问模块,其中模块的类可以被调用。

1215. Why do applications compiled with AOT (Ahead of compilation) launch faster?

为什么使用 AOT(预先编译)编译的应用启动更快?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986b6 | 官方: 否 | 付费: 否

答案:

Some of the reasons as to why applications compiled with AOT launch faster are as follows - - Application components that are compiled with AOT execute immediately, without the client-side compilation.

使用 AOT 编译的应用启动更快的一些原因如下:- 使用 AOT 编译的应用组件立即执行,无需客户端编译。
  • Templates here are embedded as code within their components. Therefore, there is no client-side request for template files, making it fast.
  • The compiler does not entertain the unused Angular directives and therefore, gives a fast response.
    Conclusion

    结论

As is evident from the above set of questions, Angular has a plethora of features that it has to offer to developers. This is the reason why Angular has been growing very rapidly and being used in the software industry.

从上述一系列问题可以看出,Angular 拥有众多可供开发者使用的功能。这就是为何 Angular 发展迅速并在软件行业中被广泛使用的原因。

Therefore, any budding developer of today, who is familiar with Angular, has a good chance of cracking technical interviews of various companies. In this article, we aimed at listing the famous interview questions on Angular 8 which we think are important and we hope we are successful in our endeavor!

因此,当今任何熟悉 Angular 的新兴开发者,都有很大机会通过各公司的技术面试。在本文中,我们旨在列出我们认为重要的 Angular 8 常见面试问题,并希望我们能够成功达成这一目标!

Additional Resource

附加资源
  • Practice Coding
  • Angular Vs React
  • Difference Between Angular and AngularJS

1216. Explain Event Binding with an appropriate example.

通过适当的示例解释事件绑定。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986b9 | 官方: 否 | 付费: 否

答案:

Event binding is a technique that is used in Angular 8 to handle the events raised from the Document Object Model (DOM), for instance, button clicks, mouse hovers, mouse moves, etc. When the DOM event happens, the specified method in the component is immediately called.

事件绑定是Angular 8中用于处理文档对象模型(DOM)引发事件(例如按钮点击、鼠标悬停、鼠标移动等)的技术。当DOM事件发生时,组件中指定的方法会立即被调用。

An example of event binding is given below -

下面给出一个事件绑定的示例 -

In this example, the raiseVolume() method from the component will be called when the button is clicked.

在此示例中,当按钮被点击时,将调用组件中的raiseVolume()方法。

1217. What do you understand about NgModules in Angular 8?

你如何理解Angular 8中的NgModules?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986bc | 官方: 否 | 付费: 否

答案:

The NgModules in Angular 8 varies from other JavaScript modules. All Angular applications have at least one module known as the AppModule. The NgModule gives us a bootstrap mechanism to launch different applications easily.

Angular 8中的NgModules与其他JavaScript模块不同。所有Angular应用都至少有一个名为AppModule的模块。NgModule为我们提供了一个引导机制,可以轻松启动不同的应用。

A few of the striking features of Angular 8 modules are as follows: - The own functionality of the NgModule can be exported and can also be utilized by other NgModules.

Angular 8模块的一些显著特点如下: - NgModule自身的功能可以被导出,也可以被其他NgModule利用。
  • Angular 8 NgModule can import functionalities from other NgModules.

1218. Justify the need for Angular 8 components.

论证Angular 8组件的必要性。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986bf | 官方: 否 | 付费: 否

答案:

In Angular, there is a list of classes with decorators known as components that usually mark their own types. They provide metadata to help Angular do a lot of things. Every application in Angular 8 has at least one component known as the root component, which is mostly used to connect page hierarchy with page DOM.

在Angular中,有一类带有装饰器的类列表,称为组件,它们通常标记自己的类型。它们提供元数据以帮助Angular完成许多事情。Angular 8中的每个应用都至少有一个名为根组件的组件,该组件主要用于将页面层级与页面DOM连接起来。

1219. What is String Interpolation in Angular 8? Explain with an example.

什么是Angular 8中的字符串插值?请举例说明。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986c2 | 官方: 否 | 付费: 否

答案:

String Interpolation is a one-way Data Binding Technique. It can be used to extract the output data from a TypeScript code to the HTML template view layer. String Interpolation displays the data from the component to the view layer in the form of curly braces.

字符串插值是一种单向数据绑定技术。它可用于将TypeScript代码中的输出数据提取到HTML模板视图层。字符串插值以花括号的形式将组件中的数据显示到视图层。

String interpolation technique adds the value of property to the component. An example of String Interpolation is shown below -

字符串插值技术将属性的值添加到组件中。字符串插值的示例如下所示 -

{{data}}

{{data}}

1220. Explain the concept of Data Binding.

解释数据绑定的概念。
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986c5 | 官方: 否 | 付费: 否

答案:

Data Binding can be best described as a technique that is used to link the application’s data to the view layer. It makes communication between the DOM (Document Object Model) and the TypeScript code of our component.

数据绑定可以最好地描述为一种用于将应用数据链接到视图层的技术。它使得DOM(文档对象模型)与我们的组件TypeScript代码之间进行通信。

In other words, data binding is a communication between the typescript code of our component and our template, which is visible to the user. Data Binding allows us to define interactive applications easily and efficiently without worrying about pushing and pulling data.

换句话说,数据绑定是我们组件的TypeScript代码与用户可见的模板之间的通信。数据绑定使我们能够轻松高效地定义交互式应用,而不必担心数据的推送和拉取。

There are two types of data binding - - One-way data-binding: One-way data binding is used to bind the data from the component to the view (Document Object Model) or vice versa. One way data binding is a unidirectional data binding method, that is, we can either bind the data from the component to the view or bind the data from the view to the component.

有两种类型的数据绑定 - - 单向数据绑定:单向数据绑定用于将数据从组件绑定到视图(文档对象模型),或者反之亦然。单向数据绑定是一种单向的数据绑定方法,即我们可以将数据从组件绑定到视图,或将数据从视图绑定到组件。
  • Two-way data binding: Two-way data binding in Angular version 8 helps the users to exchange data from the component to the view and from the view to the component. Bi-directional communication is established in this method.

1221. Write the syntax for ngIf Directive. Why is it used?

编写 ngIf 指令的语法。它为什么被使用?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986c8 | 官方: 否 | 付费: 否

答案:

The syntax of the ngIf Directive is given below

ngIf 指令的语法如下所示

>

condition is true and ngIf is true. > 条件为真且 ngIf 为真。

>

condition is false and ngIf is false. > 条件为假且 ngIf 为假。


The usage of ngIf is described below -
ngIf 的用途描述如下 -

It is a structural directive present in Angular Version 8 whose usage revolves around adding or removing HTML elements based on the expression statement. The functioning of this nglf directive is observed as follows: When the expression is true, the element is added and when the expression is false, the element is removed using this directive.

它是 Angular 8 版本中存在的一个结构型指令,其用途围绕基于表达式语句添加或移除 HTML 元素。此 ngIf 指令的功能如下:当表达式为真时,元素被添加;当表达式为假时,元素通过此指令被移除。

1222. What is the usage of NgUpgrade in Angular 8?

NgUpgrade 在 Angular 8 中的用途是什么?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986cb | 官方: 否 | 付费: 否

答案:

NgUpgrade is one of the upgrade libraries of Angular version 8 which is mostly used to integrate both Angular and AngularJS components in an application. It also helps us in bridging the gap between the Dependency Injection Systems in both AngularJS and Angular.

NgUpgrade 是 Angular 8 版本的升级库之一,主要用于在应用程序中集成 Angular 和 AngularJS 组件。它还帮助我们在 AngularJS 和 Angular 的依赖注入系统之间架起桥梁。

1223. How can we create an application in Angular version 8?

我们如何在 Angular 8 版本中创建应用程序?
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3792f58d557c902b986ce | 官方: 否 | 付费: 否

答案:

We can create an Angular 8 application using the following command

我们可以使用以下命令创建一个 Angular 8 应用程序

ng new applicationName

ng new applicationName
To install the Angular CL, we can use the following command
要安装 Angular CL,我们可以使用以下命令

npm install -g @angular/CLI

npm install -g @angular/CLI

1224. List a few key parts of the Angular 8 architecture

列出Angular 8架构的几个关键部分
  • 知识点: 前端 (主题: angular, typescript, frontend;标签: interviewbit, angular-8, topic-specific, angular, typescript, frontend)
  • 类型: technical | 难度: hard | 子类型: system-design
  • 分类: fullstack
  • id: 69b3792f58d557c902b986d1 | 官方: 否 | 付费: 否

答案:

A few key parts of the Angular 8 architecture are as follows -

Angular 8架构的几个关键部分如下 -

Angular 8 Architecture - Angular 8 MetaData - Metadata in Angular version 8 is used to decorate a class for the configuration of the expected behavior of the class.

Angular 8架构 - Angular 8元数据 - Angular版本8中的元数据用于装饰一个类,以配置该类的预期行为。
  • Angular 8 DataBinding - Data Binding is used to bind the data from the component to the template.
  • Angular 8 Components - Angular Components are building blocks of all Angular applications. Every angular application is made up of one or more Angular Components. It is basically a plain JavaScript or Typescript class along with an HTML template and an associated name.
  • Angular 8 Modules - It is a collection of related features. Angular 8 Module groups multiple components and services under a single context.
  • Angular 8 Services - Services are nothing but plain and simple Typescript or JavaScript classes that provide very specific functionalities. They help us do a single task in the best possible way so that code reusability is achieved. Rather than writing a functionality inside a component, separating it into a service makes it reusable in other components as well.
  • Angular 8 Templates - Angular 8 template is a superset of HTML (HyperText Markup Language). It includes all the features of HTML and gives us additional features to bind the component data into the HTML and to dynamically generate the HTML DOM elements.

1225. What can you say about the digest phase in AngularJS?

关于AngularJS中的digest阶段,你能说些什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98719 | 官方: 否 | 付费: 否

答案:

The digest cycle or digest phase is the most important cycle required for the data binding process. It does the task of comparing the old version of a model with its new version. Whenever a change in the scope model is found during the comparison, the model watches are fired and another digest phase is initiated until the scope model is stable.

digest循环或digest阶段是数据绑定过程中最重要的循环。它的任务是比较模型的旧版本与其新版本。在比较过程中,每当发现范围模型发生变化时,模型监视器会被触发,并启动另一个digest阶段,直到范围模型稳定为止。

The digest cycle can be triggered manually by making use of $apply() or can be triggered automatically. The digest cycle gets triggered automatically when we use the core directives of AngularJS. In case we have any external code changes, then that would require manual triggering of the digest cycle.

digest循环可以通过使用$apply()手动触发,也可以自动触发。当我们使用AngularJS的核心指令时,digest循环会自动触发。如果我们有外部代码更改,那么就需要手动触发digest循环。

The following diagram illustrates the process of the digest cycle clearly.

下图清晰地说明了digest循环的过程。

1226. What does the following code do? What are the permitted values of the restrict attribute?

下面的代码做了什么?restrict属性的允许值是什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9871c | 官方: 否 | 付费: 否

答案:

app.directive('myFirstDirective', function() {

app.directive('myFirstDirective', function() {
return {
return {
restrict: 'E',
restrict: 'E',
scope: {
scope: {
directiveInfo: '=directiveInfo'
directiveInfo: '=directiveInfo'
},
templateUrl: 'my-first-directive.html'
templateUrl: 'my-first-directive.html'
};
});
  • In the given piece of code, we have defined a custom directive called “myFirstDirective”. Based on the value of restrict, we can say that the directive is restricted only to the element names. The directive has an isolated scope which has a property called “directiveInfo” that will be getting its value from the “directiveInfo” attribute of the element directive. The view or the template URL used for making the directive work is “my-first-directive.html”.
  • Following are the possible values of the restrict attribute in AngularJS directives:
    ‘A’ - attribute names are matched.

    'A' - 属性名被匹配。
    ‘E’ - element names are matched.
    'E' - 匹配元素名称。
    ‘C’ - class names are matched.
    'C' - 匹配类名。
    ‘M’ - only comments are matched.
    'M' - 仅匹配注释。

1227. Differentiate between compile and link in AngularJS?

在AngularJS中,编译和链接有什么区别?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9871f | 官方: 否 | 付费: 否

答案:

Compile is like a service used for traversing the HTML to find all the directives and return link functions. The link does the task of combining the model with a view where any changes made to the model are reflected in the view and vice versa. More information on compile and link can be found here .

编译类似于一种服务,用于遍历HTML以查找所有指令并返回链接函数。链接则负责将模型与视图相结合,其中对模型所做的任何更改都会反映到视图中,反之亦然。有关编译和链接的更多信息可在此处找到。

1228. How does routing work in AngularJS?

AngularJS中的路由是如何工作的?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98722 | 官方: 否 | 付费: 否

答案:

Routing enables us to create different URLs according to different contents in our app which in turn enables the users of the application to bookmark the contents as per their requirements. The route is that URL that can be bookmarked. Routing also helps in developing SPA (Single Page Applications) i.e create a single HTML page and update that page dynamically as and when the user interacts.

路由使我们能够根据应用中的不同内容创建不同的URL,这进而使应用的用户能够根据其需求对内容进行书签标记。路由就是那个可以被收藏的URL。路由还有助于开发单页应用程序(SPA),即创建一个单一的HTML页面,并在用户交互时动态更新该页面。

AngularJS supports routing by making use of its routing module called “ngRoute”. This module acts according to the URL. Whenever a user requests for a specific route/URL, the routing engine of the module, also called $routeProvider , renders the view based on that URL and defines what controller acts on this view - all based on the routing rules defined.

AngularJS通过使用其名为“ngRoute”的路由模块来支持路由。该模块根据URL进行工作。每当用户请求特定路由/URL时,该模块的路由引擎(也称为$routeProvider)会根据该URL渲染视图,并定义哪个控制器作用于该视图——所有这些都基于已定义的路由规则。

Consider the below snippet:

请考虑以下代码片段:

var myApp = angular.module('routingExample', ['ngRoute']);

var myApp = angular.module('routingExample', ['ngRoute']);
myApp.config(function ($routeProvider) {
myApp.config(function ($routeProvider) {
$routeProvider.when('/', {
$routeProvider.when('/', {
templateUrl: '/login-page.html',
templateUrl: '/login-page.html',
controller: 'loginPageController'
controller: 'loginPageController'
}).when('/employee/:empName', {
}).when('/employee/:empName', {
templateUrl: '/employee-page.html',
templateUrl: '/employee-page.html',
controller: 'employeeController'
controller: 'employeeController'
}).otherwise({
}).otherwise({
redirectTo: "/"
redirectTo: "/"
});
})
In the above example, we can see that to implement routing, we need to follow the below steps: - While creating the application module, pass ‘ngRoute’ as the dependency module like below:
在上述示例中,我们可以看到,要实现路由,我们需要遵循以下步骤:- 在创建应用程序模块时,将‘ngRoute’作为依赖模块传入,如下所示:
var myApp = angular.module('routingExample', ['ngRoute']); - Next, configure the routing rules for the application module by making use of the config() method by taking the $routeProvider service as the dependency.
var myApp = angular.module('routingExample', ['ngRoute']); - 接下来,通过使用config()方法,将$routeProvider服务作为依赖,为应用程序模块配置路由规则。
  • The $routeProvider.when(path, route) method is used for configuring the rules of routing where the first parameter defines what is the request URL and the second parameter defines the object containing the template, controller, and other property details that need to function upon requesting the URL.
    In the given example, if the user requests for “/login-page.html”, then inject login-page.html into the view and use the loginPageController. For the URL “/employee/:empName” URL, the :empName refers to the URL parameter dynamically populated in the URL. The otherwise() method is used for redirecting to the default or base URL for any other requests that are not part of the rules configured.

    在给定的示例中,如果用户请求“/login-page.html”,则将login-page.html注入视图,并使用loginPageController。对于URL “/employee/:empName”,:empName指的是URL中动态填充的URL参数。otherwise()方法用于将不在已配置规则范围内的任何其他请求重定向到默认或基础URL。

1229. Write a syntax to send sample HTTP POST request in AngualrJS?

编写一个语法,在AngularJS中发送示例HTTP POST请求?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98725 | 官方: 否 | 付费: 否

答案:

To perform any AJAX calls, AngularJS makes use of the $http service. The syntax is as below:

要执行任何AJAX调用,AngularJS使用$http服务。语法如下:

$http({

$http({
method: "POST",
method: "POST",
url: "URL",
url: "URL",
data: JSON.stringify(value),
data: JSON.stringify(value),
contentType: 'application/json'
contentType: 'application/json'
}).then(function (successResponse)
}).then(function (successResponse)
{
// success callback action of the request
// 请求的成功回调操作
},function (errorResponse)
},function (errorResponse)
{
// error callback action of the request
// 请求的错误回调操作
});

1230. What is the importance of the $location service?

$location 服务的重要性是什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98728 | 官方: 否 | 付费: 否

答案:

$location is one of the built-in AngularJS services that helps to keep track of the application’s URL, parses it, and makes the value available to the controller. In case the $location value is changed in the controller, the same is reflected on the browser’s address bar. Changes to the URL on the address bar also result in reflection of the same on the $location service.

$location 是 AngularJS 内置服务之一,它有助于跟踪应用程序的 URL,解析它,并使该值可用于控制器。如果控制器中 $location 的值发生了变化,同样的变化也会反映在浏览器的地址栏上。地址栏上 URL 的变化也会导致 $location 服务中的对应变化。

1231. What is the importance of orderBy?

orderBy 的重要性是什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9872b | 官方: 否 | 付费: 否

答案:

orderBy is a built-in filter in AngularJS that helps to re-order the array items based on defined criteria. For example, if we need to sort the items based on the ascending order of price, then we can follow the below code:

orderBy 是 AngularJS 中的一个内置过滤器,有助于根据定义的条件对数组项进行重新排序。例如,如果我们需要根据价格的升序对项目进行排序,那么我们可以遵循以下代码:
    >
    • >
    • {{ item.name + ', price:' + item.price }} > {{ item.name + ', price:' + item.price }}
    • >

1232. Why do we use ng-include?

我们为什么使用 ng-include?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9872e | 官方: 否 | 付费: 否

答案:

The ng-include directive is used for helping us to embed HTML pages inside a single HTML page. For example:

ng-include 指令用于帮助我们在一个 HTML 页面中嵌入其他 HTML 页面。例如:
>
>



In the above snippet, we are trying to include/embed sample.htm and example.htm page into our current AngularJS page.
在上面的代码片段中,我们尝试将 sample.htm 和 example.htm 页面包含/嵌入到当前的 AngularJS 页面中。

1233. Is it possible to create nested controllers?

是否有可能创建嵌套控制器?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98731 | 官方: 否 | 付费: 否

答案:

Yes, it is possible to create nested controllers in AngularJS. The sample code snippet can be as shown below:

是的,在AngularJS中有可能创建嵌套控制器。示例代码片段可以如下所示:
>

{{message}} {{name}}!

>

{{message}} {{name}}!

>

Welcome to our app, {{name}}!

>

欢迎来到我们的应用,{{name}}!

>

{{message}} {{name}}! You are our esteemed guest {{name}}.

>

{{message}} {{name}}!您是我们尊贵的客人{{name}}。





1234. What are AngularJS filters?

什么是AngularJS过滤器?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98734 | 官方: 否 | 付费: 否

答案:

AngularJS filters are mainly used for formatting an expression while displaying it to the user. These can be used in controllers or services or views. AngularJS provides several inbuilt filters such as currency, filter, date, JSON, limitTo, etc whose purpose is to format the data without actually changing its value before merging to the expression and this is done by using the pipe character (|). AngularJS also provides support for registering and implementing custom filters and use them using the pipe symbol.

AngularJS过滤器主要用于在向用户显示表达式时对其进行格式化。它们可以在控制器、服务或视图中使用。AngularJS提供了几种内置过滤器,如currency、filter、date、JSON、limitTo等,其目的是在合并到表达式之前格式化数据而不实际改变其值,这是通过使用管道字符(|)来实现的。AngularJS还支持注册和实现自定义过滤器,并使用管道符号来使用它们。

Syntax for using filters:

使用过滤器的语法:

{{expression | filterName:filterInputParameter }}

{{expression | filterName:filterInputParameter }}
For example, to format data to display the currency symbol before the salary value of say 18000:
例如,要格式化数据以在工资值(比如18000)前显示货币符号:

{{salary | currency:'Rs.'}}

{{salary | currency:'Rs.'}}
The salary will be displayed as “Rs.18,000”. Here ‘Rs.’ is the input to currency filter to define formatting. If nothing is specified, the default is considered as Dollars ($).
工资将显示为“Rs.18,000”。这里“Rs.”是currency过滤器的输入,用于定义格式化方式。如果未指定,默认视为美元($)。

You can look into the implementation of different types of filters in the official documentation of AngularJS here .

您可以在此处查看AngularJS官方文档中不同类型过滤器的实现。

1235. What is the importance of track by in the ng-repeat directive?

在ng-repeat指令中,track by的重要性是什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98737 | 官方: 否 | 付费: 否

答案:

ng-repeat directive helps to keep track of all DOM elements dynamically to minimize DOM creation and rendering. It is achieved by storing the instances of the object whenever a new element gets added to the list or collection. AngularJS just renders the newly added element instead of re-rendering the overall collection. This helps in rendering the elements faster.

ng-repeat指令有助于动态跟踪所有DOM元素,以最小化DOM创建和渲染。这是通过在列表或集合中添加新元素时存储对象实例来实现的。AngularJS只渲染新添加的元素,而不是重新渲染整个集合。这有助于更快地渲染元素。

In case the ng-repeat is operated on a collection that has the objects of unique identifier, the tracking of new elements should be done based on that id instead of new instance insertion. This can be done by making use of the track by provided by the ng-repeat. For example, in the below piece of code:

如果ng-repeat操作的是一个包含唯一标识符对象的集合,那么对新元素的跟踪应基于该id进行,而不是基于新实例的插入。这可以通过使用ng-repeat提供的track by来实现。例如,在下面的代码片段中:
>
>

the tracking of new elements is done using the object’s id.
新元素的跟踪是使用对象的id来完成的。

1236. What are the different phases of the lifecycle of AngularJS Scope?

AngularJS Scope生命周期的不同阶段是什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9873a | 官方: 否 | 付费: 否

答案:

The following diagram illustrates the scope lifecycle in AngularJS:

下面的图表说明了AngularJS中的scope生命周期:
  • Creation: In this phase, the rootScope is created by $injector during the application bootstrap. During the phase of template linking, new child scopes relevant to the directives are created.
  • Watcher registration: Here, the directives register the watches on the scope object which will be used to propagate values of models to DOM.
  • Model mutation: The model mutations need to be present within the scope.$apply() for them to be properly observed. These will be done implicitly by AngularJS when working on synchronous or asynchronous work requests.
  • Mutation observation: Once the $apply is complete, the digest cycle starts to observe for any model mutations on the scopes. Here, the $watches expressions are monitored for the model mutations and if any mutations are observed, then the $watch listener is called on the model.
  • Scope destruction: As and when the child scopes are unnecessary, the creator of the scopes would have to destroy them by making use of scope.$destroy(). This ensures that the $digest cycle propagations are stopped and the memory once used by the child scopes is reclaimed.

1237. How will you improve performance of an AngularJS application?

你将如何提高AngularJS应用的性能?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9873d | 官方: 否 | 付费: 否

答案:

AngularJS makers have recommended the below two approaches for performance optimization in the production environment. They are: - Enable strict DI mode: This can be achieved by making use of the directive ngStrictDi and can be implemented as:

AngularJS开发者推荐了以下两种在生产环境中进行性能优化的方法。它们是:- 启用严格DI模式:这可以通过使用ngStrictDi指令实现,可以这样实现:
- Disable debug data: This can be achieved by using the debugInfoEnabled method of the $compileProvider service as shown below:
- 禁用调试数据:这可以通过使用$compileProvider服务的debugInfoEnabled方法来实现,如下所示:
app.config(function ($compileProvider) {
app.config(function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
$compileProvider.debugInfoEnabled(false);
});

Apart from the above two, we can also improve the performance by following the below tips: - Implementing one-time binding whenever possible.

除了上述两种方法,我们还可以通过遵循以下提示来提高性能:- 尽可能实现一次性绑定。
  • By making $httpProvider use the applyAsync feature. - - By refraining from creating many $watchers unnecessarily as too many of the watchers will lengthen the digest cycle thereby reducing the speed.
  • If you have scenarios like repeated data calculations of the same nature, then we can make use of the $cacheFactory directive to store the data to avoid recalculations.
  • In case we have a large number of elements to be looped, then instead of loading everything at once, pagination or infinite scroll can be implemented to reduce the data load. AngularJS provides ngInfiniteScroll directive for accomplishing the infinite scroll feature.
    For more information regarding the tools that can be used to measure AngularJS performance, you can read here .

    有关可用于测量AngularJS性能的工具的更多信息,您可以在此处阅读。

1238. What is the difference between the scopes of a directive and the scopes of a controller?

指令的作用域和控制器的作用域有什么区别?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98740 | 官方: 否 | 付费: 否

答案:

Scopes of the controller and the directives are the instances of scope objects. The only difference lies in the naming convention for them. To understand the difference between scope and $scope, we need to understand directives with isolated scope using the following code:

控制器和作用域指令是作用域对象的实例。它们之间的唯一区别在于命名约定。要理解scope和$scope之间的区别,我们需要通过以下代码来理解具有隔离作用域的指令:

app.directive('testAppDirective', function() {

app.directive('testAppDirective', function() {
return {
return {
scope: {},
scope: {},
link: function(myScopeVariable, elem,attr) {
link: function(myScopeVariable, elem,attr) {
console.log(scope);
console.log(scope);
}
}
});
Here, we have defined a directive with isolated scope. The link function takes the signature scope, element, and attribute as the parameters. The name of the signature scope parameter can be anything as that parameter will be tagged to the scope of the directive’s object. The $scope object that is usually injected into the controller cannot be used with another name. For example,
在这里,我们定义了一个具有隔离作用域的指令。link函数将签名scope、element和attribute作为参数。签名scope参数的名称可以是任何名称,因为该参数将被标记为指令对象的作用域。通常注入到控制器中的$scope对象不能使用其他名称。例如,

app.controller(‘myTestController’,function(newScope)

app.controller('myTestController', function(newScope)
{
});
results in error Error:
会导致错误Error:

[$injector:unpr] Unknown provider: scopeProvider <- scope <- myTestController

[$injector:unpr] Unknown provider: scopeProvider <- scope <- myTestController
Because the AngularJS dependency system tries to locate the dependency of the name newScope but fails to find it. Hence, to mark the dependency appropriately, the input to the controller function should be $scope.
因为AngularJS依赖系统试图定位名为newScope的依赖,但无法找到它。因此,为了正确标记依赖,控制器函数的输入应为$scope。

1239. How will you hide an HTML tag element on click of a button click in AngularJS? Write a program for the same.

如何在AngularJS中通过按钮点击隐藏HTML标签元素?请编写一个程序实现相同的功能。
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: coding
  • 分类: fullstack
  • id: 69b3793058d557c902b98743 | 官方: 否 | 付费: 否

答案:

This can be achieved by making use of the ng-click directive that controls the condition used for manipulating the display of the tag in the ng-hide directive.

这可以通过使用ng-click指令来实现,该指令控制用于在ng-hide指令中操作标签显示的条件。

<!DOCTYPE html>

<!DOCTYPE html>






Button Click Hide
按钮点击隐藏



>
>
InterviewBit
>
InterviewBit





1240. How can you maintain logs in AngularJS?

如何在AngularJS中维护日志?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98746 | 官方: 否 | 付费: 否

答案:

Logs in AngularJS can be maintained by using the $log built-in service. These are mainly used for troubleshooting and debugging in case of any unexpected scenarios. They are done by mainly using the below methods:

在AngularJS中,日志可以通过内置的$log服务来维护。这些主要用于在出现意外情况时进行故障排除和调试。主要通过使用以下方法来实现:
  1. log(): To log a message onto the console. Example usage: $log.log(‘Entered some function’) 2. info(): To write any message which represents information. Example usage: $log.info(‘Data processed successfully’) 3. warn(): To log warnings. Example usage: $log.warn(‘The value is empty.’) 4. error(): To log errors. Example usage: $log.error(‘Oh no! Something went wrong.’) 5. debug(): To log any debug messages useful for debugging. Example usage: $log.debug(‘Processed a variable A.’)

    1. log():用于将消息记录到控制台。示例用法:$log.log(‘进入某个函数’) 2. info():用于写入表示信息的任何消息。示例用法:$log.info(‘数据成功处理’) 3. warn():用于记录警告。示例用法:$log.warn(‘该值为空。’) 4. error():用于记录错误。示例用法:$log.error(‘哎呀!出错了。’) 5. debug():用于记录对调试有用的任何调试消息。示例用法:$log.debug(‘处理了变量A。’)

1241. How do you achieve internationalization?

你如何实现国际化?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98749 | 官方: 否 | 付费: 否

答案:

Internationalization is a way of showing locale-specific content on our applications. For example, the website in the United Kingdom needs to be displayed in English whereas the same website needs to be shown in Hindi for the users of India. By incorporating multiple languages support in our platform, we are ensuring that our website reaches a wider target audience.

国际化是一种在我们的应用程序中显示特定于区域的内容的方式。例如,英国网站需要以英语显示,而印度的用户则需要以印地语显示同一网站。通过在我们的平台中支持多种语言,我们确保网站能够触达更广泛的目标受众。

Internationalization is supported in AngularJS using the angular-translate module which has lots of filters and directives and also the ability to asynchronously load i18n based data. The module also provides support for pluralization by making use of the highly configurable MessageFormat.

AngularJS 通过使用 angular-translate 模块支持国际化,该模块具有许多过滤器和指令,并且还能异步加载基于 i18n 的数据。该模块还通过使用高度可配置的 MessageFormat 提供复数形式支持。

1242. What is the auto bootstrap process?

什么是自动引导过程?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9874c | 官方: 否 | 付费: 否

答案:

Auto Bootstrapping is the process of automatically initiating the DOMContentLoaded event in the browser. The AngularJS application after downloading the angular.js library into the browser does the task of finding the ng-app directive which gives the root of the application. Once the directive is found, the following steps take place: - The angular root module associated with the ng-app directive is loaded.

自动引导是在浏览器中自动触发 DOMContentLoaded 事件的过程。AngularJS 应用程序在将 angular.js 库下载到浏览器后,会查找提供应用程序根目录的 ng-app 指令。一旦找到该指令,将执行以下步骤: - 加载与 ng-app 指令关联的 Angular 根模块。
  • The application injector is created which in turn creates the $compile and the $rootScope objects.
  • The DOM is compiled from the ng-app element automatically and the content is rendered on the browser. This process is called auto bootstrapping.

1243. What are the lifecycle hooks available?

有哪些可用的生命周期钩子?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9874f | 官方: 否 | 付费: 否

答案:

There are many lifecycle hooks available in AngularJS and they are: - ngOnInit(): This is a callback method that gets invoked as soon as the change detector detects any scope model changes for the first time and before any view has been checked. This is invoked once only when the directive is instantiated.

AngularJS 中有许多可用的生命周期钩子,它们是: - ngOnInit():这是一个回调方法,当变更检测器首次检测到任何作用域模型更改且在任何视图被检查之前,该方法就会被调用。它只在指令被实例化时调用一次。
  • ngOnChanges(): This callback function is triggered whenever AngularJS detects changes in the scope model and we can define the actions that need to follow up with that change in the property. It is called before ngOnInit() while instantiating the directive and is called every time the scope model changes.
  • ngDoCheck(): This callback method does the task of change-detection and is invoked only after the default change-detector is run.
  • ngAfterContentInit(): This is invoked once and that too as soon as AngularJS completes the initialization of all content of the directives.
  • ngAfterContentChecked(): This callback method is invoked as soon as the default change-detector completes checking the content of the directives.
  • ngOnDestroy(): This is used to clean up any component just before the directives or its properties are destroyed. They are useful for avoiding memory leaks and unsubscribe any unnecessary observables.
  • ngAfterViewChecked(): This is immediately invoked once the default change-detector completes one cycle of change-check.

1244. What is the difference between the $ and the $$ prefixes?

$ 和 $$ 前缀之间的区别是什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98752 | 官方: 否 | 付费: 否

答案:

The $$ prefix is used to define a private variable in AngularJS. This is responsible for avoiding accidental code changes due to exposure to the variables. Examples are $$observers , $$watchers , $$childScope etc. The $ prefix is used for defining built-in core AngularJS functionalities like variable, parameter, method, or any properties. Examples are $scope , $http , $routeProvider , $watch etc.

$$ 前缀用于定义 AngularJS 中的私有变量。这负责避免因变量暴露而导致的意外代码修改。示例包括 $$observers 、$$watchers 、$$childScope 等。$ 前缀用于定义内置的 AngularJS 核心功能,例如变量、参数、方法或任何属性。示例包括 $scope 、$http 、$routeProvider 、$watch 等。

Conclusion:

结论:
In this article, we have seen the most commonly asked AngularJS interview questions for both the freshers and. the experienced developers. AngularJS was initially created to establish the concept of dependency injection and ease the development of single-page applications. Despite AngularJS being the first version, many companies have adopted this framework due to its raging benefits, easy configuration, and extensibility. Even though the framework has undergone a lot of changes in its different versions and releases, AngularJS has been the most useful framework for developing web applications in different companies.
在本文中,我们看到了最常见的新手和经验丰富的开发者都会问到的 AngularJS 面试问题。AngularJS 最初是为了建立依赖注入的概念并简化单页应用程序的开发而创建的。尽管 AngularJS 是第一版,许多公司因其显著优势、简单配置和可扩展性而采用了此框架。尽管该框架在不同版本和发布中经历了许多变化,但 AngularJS 一直是不同公司开发 Web 应用程序最有用的框架。

References:

参考文献:

Recommended Resources:

推荐资源:
  • Javascript Interview
  • Angular Interview
  • Angular 8 Interview
  • Difference Between Angular and AngularJS
  • Angular Vs React

1245. Differentiate between expressions of AngularJS and JavaScript.

区分 AngularJS 和 JavaScript 的表达式。
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98759 | 官方: 否 | 付费: 否

答案:

AngularJS expressions are placed inside double curly braces {{expression}} similar to JavaScript. The main differences between them are:

AngularJS 表达式放在双花括号 {{expression}} 中,类似于 JavaScript。它们之间的主要区别是:
AngularJS expressions
AngularJS 表达式
JavaScript expressions
JavaScript 表达式
The expressions are evaluated against the scope object that they are part of.
表达式针对它们所属的作用域对象进行评估。
The expressions are evaluated against the global window scope.
表达式针对全局窗口作用域进行评估。
Expression evaluation nature is forgiving. If something goes wrong, it returns null or undefined.
表达式评估性质是宽容的。如果出错,返回 null 或 undefined。
JavaScript expressions are not forgiving in nature and return an error.
JavaScript 表达式本质上不宽容,返回错误。
Here, loops and conditional statements cannot be added as part of expressions.
在这里,循环和条件语句不能作为表达式的一部分添加。
Loops and conditional statements can be part of JavaScript expressions.
循环和条件语句可以是 JavaScript 表达式的一部分。

1246. List out the scope characteristics in AngularJS?

列出 AngularJS 中的作用域特性?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9875f | 官方: 否 | 付费: 否

答案:

Scope object has 5 important characteristics. - It provides the application with a context against which the AngularJS expressions are evaluated.

作用域对象有 5 个重要特性。 - 它为应用程序提供了评估 AngularJS 表达式的上下文。
  • It provides an option to observe the model changes within them using the $watch watcher service.
  • The scope objects provide APIs like $apply that help in propagating the model changes throughout the application into the view from the sources like controllers, services, or various AngularJS event handlers.
  • Scope objects inherit the parent properties and provide access to shared model properties.
  • Scopes can even be nested to isolate directives and various AngularJS components.

1247. How is the mouse double click event accomplished?

鼠标双击事件是如何完成的?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98762 | 官方: 否 | 付费: 否

答案:

To specify any custom behaviour upon double click event on any HTML element, AngularJS makes use of the ng-dblclick directive. It is to be noted that the ng-dblclick does not override the JavaScript’s ondblclick event. Example usage of this directive:

要在任何 HTML 元素的双击事件上指定自定义行为,AngularJS 会使用 ng-dblclick 指令。需要注意的是,ng-dblclick 不会覆盖 JavaScript 的 ondblclick 事件。此指令的示例用法如下:



The above piece of code increments the clicked variable by 1 upon every double click on the button.
上述代码片段在每次双击按钮时将 clicked 变量递增 1。

1248. How can you reset a $timeout and disable a $watch()?

如何重置 $timeout 并禁用 $watch()?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98765 | 官方: 否 | 付费: 否

答案:

In order to reset $timeout, we call the .cancel() method on it. as shown below:

要重置 $timeout,我们对其调用 .cancel() 方法,如下所示:

var myTimer = $timeout(function() { / your code / }, 1000);

var myTimer = $timeout(function() { / your code / }, 1000);
$timeout.cancel(myTimer);
$timeout.cancel(myTimer);
To disable $watch, we can just call it as shown below:
要禁用 $watch,我们可以按如下方式调用它:

var deregisterWatch = $scope.$watch(function() { / Your code / });

var deregisterWatch = $scope.$watch(function() { / Your code / });
deregisterWatch(); // calling the watcher disables it.
deregisterWatch(); // 调用该监听器即可将其禁用。

1249. Why is the findIndex() method used? What does it return in case the value is not found?

为什么使用 findIndex() 方法?如果未找到值,它会返回什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b98768 | 官方: 否 | 付费: 否

答案:

findIndex() method returns the position of the element in any object. In case the element is not found then the method returns -1. For example:

findIndex() 方法返回任何对象中元素的位置。如果未找到该元素,则方法返回 -1。例如:

var index = $scope.objectsList.findIndex(obj => obj.date =='2021-21-06');

var index = $scope.objectsList.findIndex(obj => obj.date =='2021-21-06');
Here, the index of the object where it has the date property value equal to 2021-21-06 is returned.
这里返回的是date属性值等于2021-21-06的对象的索引。

1250. Is it possible for a parent controller to access the methods and properties of the child controller?

父控制器能否访问子控制器的方法和属性?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9876b | 官方: 否 | 付费: 否

答案:

No, the parent controller can’t access the properties and the methods of the child controller. But the child controller can access the parent’s methods.

不能,父控制器无法访问子控制器的属性和方法。但子控制器可以访问父控制器的方法。

1251. What can you tell about the given piece of code?

关于给定的这段代码,你能说明什么?
  • 知识点: 前端 (主题: angularjs, javascript, frontend;标签: interviewbit, angularjs, topic-specific, javascript, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793058d557c902b9876e | 官方: 否 | 付费: 否

答案:




The given piece of code would throw syntax error because in AngularJS it is not possible to use ng-options directives without using the ng-model directive. The ng-options dynamically generate the elements for the given element by evaluating the expression within it. Now upon selecting the element from the dropdown, the option value needs to be bound to a model which is defined by the ng-model directive. Absence of the ng-model results in error.
给定的这段代码会抛出语法错误,因为在AngularJS中,如果不使用ng-model指令,就不能使用ng-options指令。ng-options会通过计算其中的表达式,为给定的元素动态生成

1252. What are the tools used in Appium for debugging?

Appium中用于调试的工具有哪些?
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b99248 | 官方: 否 | 付费: 否

答案:

We generally use log data ( a log file is maintained wherein whenever an error occurs, it is logged into this file) to see the cause of the issue, where the failure is occurring. So for iOS – iPhone configuration utility & for Android Monitor.bat, etc can be used. If you give the developer the logs from these tools, they'll be able to figure out what's causing the problem quickly.

我们通常使用日志数据(维护一个日志文件,每当发生错误时,都会记录到该文件中)来查看问题的原因,即失败发生的位置。因此,对于iOS——可以使用iPhone配置实用工具,对于Android——可以使用Monitor.bat等工具。如果你将这些工具生成的日志提供给开发者,他们将能快速找出导致问题的原因。

Useful Resources: - Automation Testing

有用资源: - 自动化测试
  • Selenium Testing
  • Android
  • Technical Interview Guide

1253. What are the basic requirements for writing Appium tests?

编写Appium测试的基本要求是什么?
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b9924b | 官方: 否 | 付费: 否

答案:

Following are the basic requirements for writing Appium tests:- - Driver Client: Appium's driver client simulates the behaviour of a user in mobile applications. Appium tests can be built with the aid of a client library, which wraps the stages of a test and sends it to Appium over HTTP.

编写Appium测试的基本要求如下:- - 驱动客户端:Appium的驱动客户端模拟用户在移动应用中的行为。Appium测试可以借助客户端库构建,该库封装了测试的各个阶段,并通过HTTP将其发送到Appium。
  • Appium Session: Because appium tests are run within a session, it's crucial to set up an appium session first. Once the automation of a session has come to an end, it will be terminated and the user will have to wait for the next session.
  • Desired Capabilities: In order to start an appium session, it's critical to design some parameters known as desired parameters. Platform version, platform name, device name, and many others are among these parameters. This also aids in defining the type of automation that the Appium server is expected to provide.
  • Driver Commands: Appium provides the ability to build tests using a large and expressive set of commands.

1254. Mention the tests which you cannot do with an emulator but can do it with a real device.

提到哪些测试你无法在模拟器上执行,但可以在真实设备上执行。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b9924e | 官方: 否 | 付费: 否

答案:

Following are a list of tests that we may conduct on a real device but is not possible in an emulator:- - Testing for interruptions during phone calls and messages.

以下是在真实设备上可以执行但在模拟器中无法实现的测试列表:- - 测试电话和消息中断的干扰。
  • Performance of the application when the battery is low.
  • Effect of the application on battery usage.
  • A scenario where the memory card is mounted or unmounted from the device.
  • Testing involves the use of Bluetooth.

1255. Do you think that automation testing can be a complete replacement for manual software testing?

你认为自动化测试可以完全替代手动软件测试吗?
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b99251 | 官方: 否 | 付费: 否

答案:

No, automation testing cannot be a complete replacement for manual software testing. This is because the tools used are meant to execute tests once they are set up and proper automation requires as little human participation as feasible. As convenient as it is, it should not be used to replace manual testing; rather, it should be used for repetitive activities such as load testing, which requires thousands of virtual users. Engineers should not automate test scripts if they are only intended to run on a periodic basis, nor should they automate code reviews or bug testing for new software builds that may require human engagement to detect errors. To sum up, we can say that large-scale, repetitive jobs are better suited to automation.

不,自动化测试不能完全替代手动软件测试。这是因为所使用的工具旨在一旦设置好测试后就执行它们,而恰当的自动化要求尽可能少的人工参与。尽管它很方便,但不应用来取代手动测试;相反,它应用于重复性活动,如负载测试,这需要成千上万的虚拟用户。如果测试脚本仅打算定期运行,工程师不应自动化它们,也不应自动化代码审查或新软件构建的缺陷测试,这些可能需要人工参与来检测错误。总之,我们可以说,大规模、重复性的工作更适合自动化。

1256. Differentiate between Appium and Selenium.

区分Appium和Selenium。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b99254 | 官方: 否 | 付费: 否

答案:

Selenium: Selenium is an open-source (free) automated testing framework for validating web applications across multiple browsers and platforms. Selenium Test Scripts can be written in a variety of programming languages, including Java, C#, Python, and others.

Selenium:Selenium是一个开源(免费)的自动化测试框架,用于验证跨多种浏览器和平台的Web应用。Selenium测试脚本可以用多种编程语言编写,包括Java、C#、Python等。

Following are the differences between Appium and Selenium:-

Appium和Selenium之间的区别如下:-

Based on Usage: - Appium - Appium is a popular open-source for automation testing, notably in native applications such as Android and iOS apps. It can also be used in hybrid applications that run in both Android and iOS environments. This type of automation testing assures that no systemic issues arise as a result of any specific patch installation once the app has gone live in production. It assures complete integration testing and avoids a significant amount of manual labour on the tester's part. By using Appium, users can easily avoid manually testing each and every feature of the entire application every time.

基于用途:- Appium - Appium 是一种流行的开源自动化测试工具,尤其适用于诸如 Android 和 iOS 应用等原生应用程序。它还可用于在 Android 和 iOS 环境中运行的混合应用程序。这种自动化测试确保应用上线后,任何特定补丁安装都不会引发系统性问题的出现。它确保完整的集成测试,并显著减少测试人员的大量手工劳动。通过使用 Appium,用户可以轻松避免每次对手动测试整个应用的每个功能。
  • Selenium - Selenium is a common automated testing tool that is built for any type of web application. It is compatible with all current popular browsers and operating systems such as Windows, Linux, and MACOS.
    Based on Design: - Appium - Appium is primarily intended as an HTTP server because it will handle any type of mobile app. However, it is primarily following or developing the same in node JS, rather than utilising standard Java or JS code. As a result, developers who want to utilise Appium for automated testing in any type of mobile app must first install Node JS on their system before using the Appium tool.

    基于设计:- Appium - Appium 主要被设计为 HTTP 服务器,因为它能处理任何类型的移动应用。然而,它主要遵循或使用 Node JS 进行开发,而非利用标准的 Java 或 JS 代码。因此,希望利用 Appium 对任何类型的移动应用进行自动化测试的开发者,在使用 Appium 工具之前,必须在其系统上安装 Node JS。
  • Selenium - Selenium is primarily used for maintaining automation logic on web applications or webpages. It is created in such a way that it may interact with the application quickly and easily by using browser activities.

1257. Differentiate between Appium and Calabash.

区分 Appium 和 Calabash。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b99257 | 官方: 否 | 付费: 否

答案:

Calabash : Calabash is an automation framework for automating user interface acceptance tests. It works with a variety of mobile systems, including iOS and Android. This can be used to automate a variety of mobile applications, including native, mobile web, and hybrid.

Calabash:Calabash 是一个用于自动化用户界面验收测试的自动化框架。它支持多种移动操作系统,包括 iOS 和 Android。它可用于自动化多种移动应用程序,包括原生、移动网页和混合应用。

Following are the differences between Appium and Calabash:-

以下是 Appium 和 Calabash 之间的区别:-
Basic
基础
AppiumCalabash
Programming Languages Supported
支持的编程语言
Java, Python, JavaScript,.Net, Ruby, and all other major programming languages are supported by Appium.
Appium 支持 Java、Python、JavaScript、.Net、Ruby 以及所有其他主要编程语言。
The Ruby programming language is the only one supported by Calabash.
Calabash 仅支持 Ruby 编程语言。
iOS mobile web page
iOS 移动网页
It necessitates the creation of a custom safari application for automation.
它需要创建自定义的 Safari 应用来进行自动化。
Calabash does not support it yet.
Calabash 尚不支持此功能。
Native iOS application
原生 iOS 应用
It requires only the iOS UI Automator.
它仅需要 iOS UI Automator。
It requires iOS instrumentation for this.
它需要 iOS 仪器化工具。
Hybrid iOS application
混合 iOS 应用
It necessitates the use of custom UI commands and the iOS UI Automator.
它需要使用自定义 UI 命令和 iOS UI Automator。
It necessitates the use of custom UI commands as well as an iOS framework.
它需要使用自定义 UI 命令以及 iOS 框架。
Hybrid Android application
混合 Android 应用
Only the Selendroid application is required.
仅需要 Selendroid 应用。
Android instrumentation is required - calabash android.
需要 Android 仪器化工具 - calabash android。
Android mobile web application
Android 移动网页应用
It can be used to automate only the chrome browser.
它仅能用于自动化 Chrome 浏览器。
It is not supported by Calabash.
Calabash 不支持此功能。
Native Android application
原生 Android 应用
Both Android UI Autometer and Selendroid are required by Appium.
Appium 需要 Android UI Automator 和 Selendroid 两者。
Android instrumentation is required - calabash android.
需要 Android 仪器化工具 - calabash android。

1258. Differentiate between open source tools, vendor tools and in house tools.

区分开源工具、供应商工具和内部工具。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b9925a | 官方: 否 | 付费: 否

答案:

  • Open Source Tools: Open source tools are frameworks and apps that are free to use. Engineers construct this tool and give it free on the internet for other engineers, developers, or enthusiasts to develop and use, which is incredibly beneficial for aspiring developers.
  • Vendor Tools: Vendor tools are created by companies that have a license to utilize their tools and codes. Technical support is accessible via the internet for these tools.
  • In House Tools: In-house tools are the tools that a corporation develops for its own usage and self-development. They are never made available to the general population.

1259. Differentiate between Appium and Robotium.

区分 Appium 和 Robotium。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b9925d | 官方: 否 | 付费: 否

答案:

Robotium: Robotium is a testing framework for Android that automates test cases for native and hybrid apps. The developer can use Robotium to construct robust automatic Graphical User Interface (GUI) testing cases for Android applications. A developer might also design a functional, system, and acceptability test scenario, which would cover a wide range of Android activities.

Robotium:Robotium 是一个用于 Android 的测试框架,可自动化原生和混合应用的测试用例。开发者可以使用 Robotium 为 Android 应用构建强大的自动图形用户界面(GUI)测试用例。开发者还可以设计功能、系统和可接受性测试场景,这些场景可覆盖广泛的 Android 活动。

Following are the differences between Appium and Robotium:-

以下是 Appium 和 Robotium 之间的区别:-
  • Appium is a cross-platform testing tool that works on both iOS and Android devices. Robotium, on the other hand, is limited to Android.
  • Robotium only supports the Java programming language, but Appium supports a variety of languages.
  • The Appium tool does not require any application source code or libraries, whereas the Robotium tool does.
  • Appium can test native, web, and hybrid mobile apps, whereas Robotium can only test native and hybrid mobile apps.
  • Many frameworks, such as Selenium, are supported by Appium. Robotium, on the other hand, is incompatible with Selenium and many other frameworks.
  • You don't have to reinstall Appium every time you make a little modification. However, a simple change in Robotium code necessitates a complete rebuild.

1260. Differentiate between Appium and Selendroid.

区分 Appium 和 Selendroid。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b99260 | 官方: 否 | 付费: 否

答案:

Selendroid: Selendroid is a cutting-edge test automation framework for testing native and hybrid Android mobile apps. The test is created using the Selenium 2 client API and is driven by the user interface of a mobile or web app. Selendroid is a dynamic mobile testing framework that can be used on emulators as well as real Android smartphones, with the option of integrating as a node in Selenium Grip for parallel testing and scaling.

Selendroid:Selendroid 是一个尖端的测试自动化框架,用于测试原生和混合的 Android 移动应用。测试使用 Selenium 2 客户端 API 创建,并由移动或网页应用的用户界面驱动。Selendroid 是一个动态的移动测试框架,可在模拟器和真实 Android 智能手机上使用,并可选集成到 Selenium Grid 中作为节点,以进行并行测试和扩展。

Following are the differences between Appium and Selendroid:

以下是 Appium 和 Selendroid 之间的区别:
  • Appium is an open-source automation solution that works on both iOS and Android, whereas Selendroid is an Android-only test automation framework.
  • A minor modification in Appium does not necessitate reinstalling the application. However, Selendroid requires the application to be reinstalled even after a minor modification..
  • Appium has a large and active community of active developers, whereas Selendroid does not have one.
  • Appium is compatible with a wide range of frameworks and languages. Selendroid, on the other hand, works with Jenkin and Selenium.
  • Appium does not necessitate the use of application source code or libraries, unlike Selendroid does.
  • Appium supports all Android APIs. Appium uses UIAutomator for tests that run on APIs greater than or equal to 17, and Selendroid for tests that run on older APIs. Selendroid, on the other hand, has different versions corresponding to the different versions of the Android APIs.

1261. Explain how Appium works.

解释 Appium 的工作原理。
  • 知识点: 前端 / 测试 (主题: appium, mobile-testing;标签: interviewbit, appium, topic-specific, mobile-testing)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3793b58d557c902b99263 | 官方: 否 | 付费: 否

答案:

When we install Appium on our PC, it also installs a server that exposes the REST API. It accepts commands and connection requests from the client and executes them on iOS or Android devices. It responds to HTTP requests with HTTP responses. It runs the user interface of the app using a mobile test automation framework to perform requests. As an example -

当我们在 PC 上安装 Appium 时,它还会安装一个暴露 REST API 的服务器。它接受来自客户端的命令和连接请求,并在 iOS 或 Android 设备上执行这些请求。它用 HTTP 响应来响应 HTTP 请求。它使用移动测试自动化框架运行应用的用户界面来执行请求。例如——

UIAutomator is used for Android API 16 or higher, while Selendroid is used for Android API 15 or below. Apple Instruments is used for iOS.

UIAutomator 用于 Android API 16 或更高版本,而 Selendroid 用于 Android API 15 或更低版本。Apple Instruments 用于 iOS。

Working of Appium on Android:

Appium 在 Android 上的工作原理:

Appium sends the command to a UIAutomator script running on the device on Android. UIAutomator is an Android native UI automation framework that allows you to run Junit test cases straight from the command line on the device. Despite the fact that it is written in Java, Appium can be run from any WebDriver enabled language.

Appium 将命令发送到设备上运行的 UIAutomator 脚本。UIAutomator 是一个 Android 原生 UI 自动化框架,允许你直接从设备上的命令行运行 Junit 测试用例。尽管它是用 Java 编写的,但 Appium 可以从任何支持 WebDriver 的语言中运行。

Android makes use of bootstrap.jar, a TCP server. It's used to deliver test commands to an Android device, which UIAutomator then executes.

Android 使用 bootstrap.jar,一个 TCP 服务器。它用于向 Android 设备传递测试命令,然后由 UIAutomator 执行。

In the above image, we can clearly see the architecture of Appium used for running on Android devices.

在上图中,我们可以清晰地看到 Appium 用于 Android 设备运行的架构。

Working of Appium on iOS:

Appium 在 iOS 上的工作原理:

As Android uses UIAutomator, iOS uses UIAutomation. Similar to the Android, Appium proxies the command to a UIAutomation test case running on the Mac instruments environment. Apple provides this application " instrument " that performs various activities like building, profiling, and controlling iOS apps. On the other hand, it also has an automation component where you can write commands in JavaScript. It uses UIAutomation API to interact with Application UI. Appium uses the same libraries to automate iOS Apps.

如同 Android 使用 UIAutomator,iOS 使用 UIAutomation。与 Android 类似,Appium 将命令代理到 Mac instruments 环境中运行的 UIAutomation 测试用例。Apple 提供了这个名为“instrument”的应用程序,用于执行构建、性能分析和控制 iOS 应用等各种活动。另一方面,它还有一个自动化组件,你可以在其中用 JavaScript 编写命令。它使用 UIAutomation API 与应用 UI 交互。Appium 使用相同的库来自动化 iOS 应用。

In the above image, we can clearly see the architecture of Appium used for running on iOS devices.

在上图中,我们可以清晰地看到 Appium 用于 iOS 设备运行的架构。

1262. What are the important rules that you should follow while using Grids in Bootstrap?

在 Bootstrap 中使用 Grid 时,应遵循哪些重要规则?
  • 知识点: 前端 (主题: bootstrap, css, frontend;标签: interviewbit, bootstrap, topic-specific, css, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3799158d557c902b9d4fd | 官方: 否 | 付费: 否

答案:

The following three rules should be strictly kept in mind while using Grids in Bootstrap:- - A row's immediate child must be a Column.

在 Bootstrap 中使用 Grid 时,应严格牢记以下三条规则:- - 某行的直接子元素必须是列。
  • Rows are just used to contain Columns and are not utilized for anything else.
  • Rows should be put within a container.

1263. Discuss the properties of flexbox

讨论 flexbox 的属性
  • 知识点: 前端 (主题: bootstrap, css, frontend;标签: interviewbit, bootstrap, topic-specific, css, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3799158d557c902b9d506 | 官方: 否 | 付费: 否

答案:

The properties of flexbox are: - Enable flex behaviors:

flexbox 的属性包括:- 启用 flex 行为:
To make a flexible container and convert direct children elements into flex items, use the "display" utility.
要创建弹性容器并将直接子元素转换为 flex 项,请使用“display”实用程序。

Additional flex characteristics can be used to further customize flex containers and items.

可以使用其他 flex 特性进一步自定义 flex 容器和项。

Default flexbox container:

默认的 flexbox 容器:
flexbox container
flexbox 容器

You can also create an inline flexbox container. Responsive variations also exist. - Direction:
您还可以创建内联 flexbox 容器。响应式变体也存在。- 方向:
You can use direction utilities to change the direction of a flex item in a flex container. It is not essential to create a horizontal class because it is set to row by default.
您可以使用方向工具类来更改 flex 容器中 flex 项的方向。无需创建水平类,因为默认设置为行方向。

To show the flex items horizontally, use .flex-row (side by side). To right-align the horizontal direction, use .flex-row-reverse.

要水平显示 flex 项,请使用 .flex-row(并排显示)。要右对齐水平方向,请使用 .flex-row-reverse。

Use .flex-column to display flex items vertically (on top of each other), or .flex-column-reverse to display them in the other direction. - Justify content:

使用 .flex-column 垂直显示 flex 项(上下堆叠),或使用 .flex-column-reverse 以相反方向显示。- 内容对齐:
To adjust the alignment of flex elements, use the.justify-content-* classes. Start (default), end, center, between, and around are all valid classes.
要调整 flex 元素的对齐方式,请使用 .justify-content-* 类。start(默认)、end、center、between 和 around 都是有效的类。
  • Align items:

You can change the vertical alignment of single rows of flex items with the .align-items-* classes. .align-items-start, .align-items-end, .align-items-center, .align-items-baseline, and .align-items-stretch (default) are valid classes.

您可以使用 .align-items-* 类更改单行 flex 项的垂直对齐方式。.align-items-start、.align-items-end、.align-items-center、.align-items-baseline 和 .align-items-stretch(默认)是有效的类。
  • Align self:

You can change the vertical alignment of a specific flex item with the .align-self-* classes. .align-self-start, .align-self-end, .align-self-center, .align-self-baseline, and .align-self-stretch (default) are valid classes.

您可以使用 .align-self-* 类更改特定 flex 项的垂直对齐方式。.align-self-start、.align-self-end、.align-self-center、.align-self-baseline 和 .align-self-stretch(默认)是有效的类。
  • Auto margins:

You can easily add auto margins to flex items with .mr-auto which pushes items to the right, or by using .ml-auto which pushes items to the left.

您可以轻松地向 flex 项添加自动边距,使用 .mr-auto 将项向右推,或使用 .ml-auto 将项向左推。
  • Grow:

You can use .flex-grow-1 on a flex item to take up the unused space. In the example below, the second flex item uses all the available space since we have used the .flex-grow-1 class with the second flex item.

您可以在 flex 项上使用 .flex-grow-1 来占用未使用的空间。在下面的示例中,第二个 flex 项使用了所有可用空间,因为我们对第二个 flex 项使用了 .flex-grow-1 类。

You can use .flex-shrink-1 on a flex item to make it shrink if required. - Fill:

您可以在 flex 项上使用 .flex-shrink-1,使其在需要时收缩。- 填充:
You can use .flex-fill on flex items to make them into equal widths. - Wrap:
您可以在 flex 项上使用 .flex-fill 使其宽度相等。- 换行:
With .flex-nowrap (default), .flex-wrap, or .flex-wrap-reverse, you can control how flex items wrap in a flex container.
使用 .flex-nowrap(默认)、.flex-wrap 或 .flex-wrap-reverse,您可以控制 flex 容器中 flex 项的换行方式。
  • Order:

With the .order classes, you can change the visual order of a given flex item(s). The number of valid classes ranges from 0 to 12, with the lowest number having the highest importance (order-1 is shown before order-2, etc..).

使用 .order 类,您可以更改给定 flex 项的视觉顺序。有效类的数量范围从 0 到 12,数字越低优先级越高(order-1 在 order-2 之前显示,等等)。
  • Align content:

You can change the vertical alignment of gathered flex items with the .align-content-* classes. .align-content-start (default), .align-content-end, .align-content-center, .align-content-baseline, and .align-content-stretch are valid classes.

您可以使用 .align-content-* 类更改聚集 flex 项的垂直对齐方式。.align-content-start(默认)、.align-content-end、.align-content-center、.align-content-baseline 和 .align-content-stretch 是有效的类。

1264. What classes can help you change the default settings of positioning a popover and closing a popover?

哪些类可以帮助您更改定位弹出框和关闭弹出框的默认设置?
  • 知识点: 前端 (主题: bootstrap, css, frontend;标签: interviewbit, bootstrap, topic-specific, css, frontend)
  • 类型: technical | 难度: hard | 子类型: concept
  • 分类: fullstack
  • id: 69b3799158d557c902b9d50a | 官方: 否 | 付费: 否

答案:

The popover will show on the right side of the element by default. To position the popover on the top, bottom, left, or right side of the element, use the data-placement attribute.

默认情况下,弹出框会显示在元素的右侧。要将其定位在元素的顶部、底部、左侧或右侧,请使用 data-placement 属性。

When you click on the element again, the popover closes by default. However, the data-trigger="focus" attribute can be used to close the popover when the user clicks outside the element.

当您再次点击该元素时,弹出框默认会关闭。然而,可以使用 data-trigger="focus" 属性,以便在用户点击元素外部时关闭弹出框。

Use the data-trigger attribute with the value "hover" if you want the popover to appear when you move the mouse cursor over the element.

如果您希望在鼠标光标移到元素上时显示弹出框,请使用值为 "hover" 的 data-trigger 属性。
0

评论

博主关闭了当前页面的评论
EN