30 Seconds of Interviews Flashcards
What is the purpose of the alt attribute on images?
The alt attribute provides alternative information for an image if a user cannot view it. The alt attribute should be used to describe any images except those which only serve a decorative purpose, in which case it should be left empty.
Good to hear
- Decorative images should have an empty alt attribute.
- Web crawlers use alt tags to understand image content, so they are considered important for Search Engine Optimization (SEO).
- Put the . at the end of alt tag to improve accessibility.
What is CSS BEM?
The BEM methodology is a naming convention for CSS classes in order to keep CSS more maintainable by defining namespaces to solve scoping issues. BEM stands for Block Element Modifier which is an explanation for its structure. A Block is a standalone component that is reusable across projects and acts as a “namespace” for sub-components (Elements). Modifiers are used as flags when a Block or Element is in a certain state or is different in structure or style.
What is the purpose of cache-busting and how can you achieve it?
Browsers have a cache to temporarily store files on websites so they don’t need to be re-downloaded again when switching between pages or reloading the same page. The server is set up to send headers that tell the browser to store the file for a given amount of time. This greatly increases website speed and preserves bandwidth.
However, it can cause problems when the website has been changed by developers because the user’s cache still references old files. This can either leave them with old functionality or break a website if the cached CSS and JavaScript files are referencing elements that no longer exist, have moved or have been renamed.
Cache busting is the process of forcing the browser to download the new files. This is done by naming the file something different to the old file.
A common technique to force the browser to re-download the file is to append a query string to the end of the file.
- src=”js/script.js” => src=”js/script.js?v=2”
The browser considers it a different file but prevents the need to change the file name.
What are the advantages of using CSS preprocessors?
CSS preprocessors add useful functionality that native CSS does not have, and generally make CSS neater and more maintainable by enabling DRY (Don’t Repeat Yourself) principles. Their terse syntax for nested selectors cuts down on repeated code. They provide variables for consistent theming (however, CSS variables have largely replaced this functionality) and additional tools like color functions (lighten, darken, transparentize, etc), mixins, and loops that make CSS more like a real programming language and gives the developer more power to generate complex CSS.
Good to hear
- They allow us to write more maintainable and scalable CSS
- Some disadvantages of using CSS preprocessors (setup, re-compilation time can be slow etc.)
What is the difference between the equality operators == and ===?
Triple equals (===) checks for strict equality, which means both the type and value must be the same. Double equals (==) on the other hand first performs type coercion so that both operands are of the same type and then applies strict comparison.
Good to hear
- Whenever possible, use triple equals to test equality because loose equality == can have unintuitive results.
- Type coercion means the values are converted into the same type.
- Mention of falsy values and their comparison.
What is the difference between an element and a component in React?
An element is a plain JavaScript object that represents a DOM node or component. Elements are pure and never mutated, and are cheap to create.
A component is a function or class. Components can have state and take props as input and return an element tree as output (although they can represent generic containers or wrappers and don’t necessarily have to emit DOM). Components can initiate side effects in lifecycle methods (e.g. AJAX requests, DOM mutations, interfacing with 3rd party libraries) and may be expensive to create.
```const Component = () => “Hello”
const componentElement =
const domNodeElement =
```
Good to hear
- Elements are immutable, plain objects that describe the DOM nodes or components you want to render.
- Components can be either classes or functions, that take props as an input and return an element tree as the output.
Using flexbox, create a 3-column layout where each column takes up a col-{n} / 12 ratio of the container.
Set the .row parent to display: flex; and use the flex shorthand property to give the column classes a flex-grow value that corresponds to its ratio value.
```.row { display: flex; }
.col-2 { flex: 2; }
.col-7 { flex: 7; }
.col-3 { flex: 3; }```
Can a web page contain multiple elements? What about elements?
Yes to both. The W3 documents state that the tags represent the header() and footer() areas of their nearest ancestor “section”. So not only can the page contain a header and a footer, but so can every and element.
Good to hear
- W3 recommends having as many as you want, but only 1 of each for each “section” of your page, i.e. body, section etc.
Briefly describe the correct usage of the following HTML5 semantic elements: , ,,
- is used to contain introductory and navigational information about a section of the page. This can include the section heading, the author’s name, time and date of publication, table of contents, or other navigational information.
- is meant to house a self-contained composition that can logically be independently recreated outside of the page without losing its meaning. Individual blog posts or news stories are good examples.
- is a flexible container for holding content that shares a common informational theme or purpose.
- is used to hold information that should appear at the end of a section of content and contain additional information about the section. Author’s name, copyright information, and related links are typical examples of such content.
Good to hear
- Other semantic elements are and
What does lifting state up in React mean?
When several components need to share the same data, then it is recommended to lift the shared state up to their closest common ancestor. For example, if two child components share the same data, it is recommended to move the shared state to parent instead of maintaining the local state in both child components.
Can you name the four types of @media properties?
- all, which applies to all media type devices
- print, which only applies to printers
- screen, which only applies to screens (desktops, tablets, mobile etc.)
- speech, which only applies to screenreaders
What is the difference between the postfix i++ and prefix ++i increment operators?
Both increment the variable value by 1. The difference is what they evaluate to.
The postfix increment operator evaluates to the value before it was incremented.
let i = 0
i++ // 0
// i === 1
The prefix increment operator evaluates to the value after it was incremented.
let i = 0
++i // 1
// i === 1
In which states can a Promise be?
A Promise is in one of these states:
- pending: initial state, neither fulfilled nor rejected.
- fulfilled: meaning that the operation completed successfully.
- rejected: meaning that the operation failed.
A pending promise can either be fulfilled with a value, or rejected with a reason (error). When either of these options happens, the associated handlers queued up by a promise’s then method are called.
How do you write comments inside a JSX tree in React?
Comments must be wrapped inside curly braces {} and use the /* */ syntax.
const tree = (
{/* Comment */}
Text
)
What is a stateful component in React?
A stateful component is a component whose behavior depends on its state. This means that two separate instances of the component if given the same props will not necessarily render the same output, unlike pure function components.
// Stateful class component class App extends Component { constructor(props) { super(props) this.state = { count: 0 } } render() { // … } } // Stateful function component function App() { const [count, setCount] = useState(0) return // … }
Good to hear
- Stateful components have internal state that they depend on.
- Stateful components are class components or function components that use stateful Hooks.
- Stateful components have their state initialized in the constructor or with useState().