D2【英】【问答格式】【精简版】每日一练前端
Q1. Explain what is a closure.
- A closure is a function having access to the parent scope, even after the parent function has closed.
Q2. Explain the difference between a controlled vs uncontrolled component.
- Controlled Component: is under control of the component's state. It stores the value by using
useState() hook.
- Uncontrolled Component: is under control of DOM. It accesses the value by using
useRef() hook.
Q3. What are meta tags in HTML?
<meta> tags always go inside the<head>element, and are typically used to specify like character set, viewport settings.
Q4. What's the difference between HTTP vs HTTPS?
- Compared to HTTP, HTTPS has SSL which can encrypt the data which the client transmits to the server. So HTTPS is much more secure than HTTP. We should use HTTPS to transmit sensitive data.
Q5. What is Cross Site Scripting (XSS)?
- Attackers inject malicious scripts into websites, so that other users who are visiting that website can be attacked, like their senstive information like cookies, sesstion tokens can be accessed by the attackers.
Q6. What is Cross-Origin Resoure Sharing (CORS)?
- It's a mechanism that allows restricted resources on a web page to be accessed from another domain outside the domain. We can indicate any origins other than its own so that those origins are allowed to load resources from this website.
Q7. What is a single-page application (SPA)?
- It's a web application that has only a single web document, and then updates the content by ajax, without reloading the whole page. It uses routing to switch to another component.
Q8. How to minimize loading time for a page?
- First, we can use CDN to make the users receive the content faster.
- We can compress css files and combine multiple css files to decrease the number of http request.
- We can use the cache-control reasonably.
- For js, we can use add defer to the script so that the js won't block html parsing.