Web Developer 面试题与答案
问题 36. What is the purpose of the 'role' attribute in HTML?
The 'role' attribute is used to define the purpose or type of an element for accessibility, helping assistive technologies interpret content.
Example:
问题 37. Explain the concept of 'WebSockets' and how they differ from HTTP.
WebSockets provide a full-duplex communication channel over a single, long-lived connection, enabling real-time communication between the client and server, unlike the request-response nature of HTTP.
问题 38. What is the purpose of the 'fetch' API in JavaScript?
The 'fetch' API is used to make HTTP requests and handle responses in a more flexible and modern way compared to the traditional 'XMLHttpRequest'.
Example:
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
问题 39. Explain the concept of 'Cross-site Scripting (XSS)' and how to prevent it.
XSS is a security vulnerability where attackers inject malicious scripts into web pages. To prevent it, developers should sanitize user input, use proper encoding, and implement Content Security Policy (CSP).
问题 40. What is the purpose of the 'transition' property in CSS?
The 'transition' property is used to create smooth transitions between different property values, allowing for animation effects.
Example:
div {
transition: width 2s, height 2s;
}
用户评价最有帮助的内容: