Building strong foundational knowledge in frontend development topics
These topics are essential for building strong foundational knowledge, and each comes with a simple solution or code snippet to illustrate the concept.
1. What is the difference between HTML, CSS, and JavaScript?
- Answer:
- HTML (Hypertext Markup Language) is used for structuring web content (headings, paragraphs, images, links, etc.).
- CSS (Cascading Style Sheets) is used for styling the layout, design, and appearance of the web content.
- JavaScript is used for adding interactivity and dynamic behavior to the website (e.g., form validation, animations, events).
2. What are semantic HTML elements and why are they important?
- Answer:
- Semantic HTML elements clearly describe their meaning in a human-readable way and help search engines and developers understand the content structure better.
- Examples include
<header>
,<footer>
,<article>
,<section>
, and<main>
. - They improve SEO, accessibility, and code readability.
3. What is the box model in CSS?
- Answer:
The CSS box model defines how the size of elements is calculated. It consists of:
- Content: The actual content (text, image, etc.)
- Padding: Space between content and border
- Border: Surrounds padding (if specified)
- Margin: Space outside the border, separating elements
- Understanding the box model is essential for controlling layout.
4. What is the difference between class
and id
in CSS?
- Answer:
- The
id
is unique and should only be used for a single element on the page (e.g.,id="header"
). - The
class
can be used multiple times to apply styles to multiple elements (e.g.,class="box"
). id
has higher specificity thanclass
in CSS.
- The
5. What is the difference between inline and block elements in HTML?
- Answer:
- Inline elements do not start on a new line and take up only as much width as necessary (e.g.,
<span>
,<a>
). - Block elements start on a new line and take up the full width available (e.g.,
<div>
,<p>
).
- Inline elements do not start on a new line and take up only as much width as necessary (e.g.,
6. What is the CSS display
property and its common values?
- Answer:
- The
display
property specifies how elements are displayed on the page. - Common values:
block
: Element takes up full width.inline
: Element takes up only necessary width.inline-block
: Combines block and inline behaviors.none
: Hides the element.
- The
7. What is the position
property in CSS and its types?
- Answer:
The
position
property defines how an element is positioned on the page.static
: Default value, no special positioning.relative
: Positioned relative to its normal position.absolute
: Positioned relative to the nearest positioned ancestor.fixed
: Positioned relative to the viewport.sticky
: Switches between relative and fixed, based on scroll position.
8. What are JavaScript Data Types?
- Answer: JavaScript has primitive and non-primitive data types:
- Primitive types:
String
,Number
,Boolean
,Null
,Undefined
,Symbol
,BigInt
. - Non-primitive types:
Object
,Array
,Function
.
- Primitive types:
9. What is the difference between let
, const
, and var
in JavaScript?
- Answer:
**let**
: Block-scoped and can be reassigned.**const**
: Block-scoped, but cannot be reassigned.**var**
: Function-scoped, can be redeclared in the same scope.
10. What is a CSS Transition?
- Answer:
A CSS Transition allows you to change property values smoothly (over a specified duration) when a specific event occurs (e.g., hover).
11. What is a CSS Animation?
- Answer:
CSS Animations allow you to animate an element's properties over time. They consist of
@keyframes
that define the changes during the animation.
12. What is a Web API in the context of JavaScript?
- Answer:
Web APIs are browser-provided interfaces that allow JavaScript to interact with the browser and perform actions like making HTTP requests (using
fetch
), manipulating the DOM, handling local storage, or interacting with the user's device (e.g., Geolocation API).- Example:
- Example:
13. What is the difference between localStorage
and sessionStorage
?
- Answer:
- localStorage: Stores data with no expiration time. Data remains available even after the browser is closed.
- sessionStorage: Stores data for the duration of the page session (until the browser is closed).
14. What are JavaScript Functions and why are they important?
- Answer:
Functions are blocks of reusable code that perform specific tasks. They can take inputs (parameters) and return outputs (values). Functions help avoid code repetition and improve modularity.
15. What is the this
keyword in JavaScript?
Answer: The
this
keyword refers to the current context of execution. It can refer to different objects depending on how the function is invoked:- In a method,
this
refers to the object the method is called on. - In a regular function,
this
refers to the global object (in non-strict mode). - In arrow functions,
this
is lexically bound, meaning it refers to the surrounding context.
- In a method,
16. What is an Event Listener in JavaScript?
- Answer:
An Event Listener is a function that waits for an event to occur on an element and runs when the event is triggered (e.g.,
click
,mouseover
,keydown
).
***************************************************************
1. CSS Flexbox Basics
- Topic: What is Flexbox and how to use it for responsive layouts?
- Solution: Demonstrate the basic usage of Flexbox for aligning items within a container.
2. CSS Grid Basics
- Topic: How to create a simple grid layout with CSS Grid?
- Solution: Show a basic grid layout with
grid-template-columns
andgrid-template-rows
.
3. CSS Transitions
- Topic: How to add smooth transitions in CSS (e.g., hover effect)?
- Solution: Show how to apply a transition effect on hovering a button.
4. JavaScript Arrow Functions
- Topic: What are arrow functions in JavaScript and why should you use them?
- Solution: Compare regular functions and arrow functions.
5. Event Delegation in JavaScript
- Topic: What is event delegation and why is it useful?
- Solution: Show how to handle events on dynamically added elements.
6. JavaScript Debouncing
- Topic: How to debounce input events to prevent multiple function calls?
- Solution: Show a simple debounce function to optimize event listeners (e.g., for search input).
7. CSS Variables (Custom Properties)
- Topic: How to use CSS variables for theming and reusability?
- Solution: Show how to define and use CSS variables for consistent styling.
8. LocalStorage vs SessionStorage
- Topic: What is the difference between
localStorage
andsessionStorage
in JavaScript? - Solution: Show examples of both
localStorage
andsessionStorage
with saving and retrieving data.
9. CSS Box Model
- Topic: How the CSS box model works and how to manage margins, padding, and borders?
- Solution: Visualize the CSS box model and its components.
10. JavaScript Map vs. Object
- Topic: What is the difference between a JavaScript
Map
and anObject
? - Solution: Show a basic comparison of both.
11. Responsive Web Design with Media Queries
- Topic: How to make a website responsive using CSS media queries?
- Solution: Demonstrate a simple layout change for mobile view.
12. Handling Form Validation in JavaScript
- Topic: How to perform basic form validation with JavaScript?
- Solution: Show a basic form validation example.
13. CSS Pseudo-classes: :hover, :focus, and :active
- Topic: How to use CSS pseudo-classes for interactivity?
- Solution: Demonstrate styling changes on
:hover
,:focus
, and:active
.
14. Using Icons with Font Awesome
- Topic: How to use Font Awesome icons in a project?
- Solution: Demonstrate adding Font Awesome icons to HTML and styling them.
15. JavaScript Template Literals
- Topic: What are template literals in JavaScript and how to use them?
- Solution: Show how to use template literals for string interpolation.
16. CSS :nth-child Selector
- Topic: How to style specific child elements with the
:nth-child
selector? - Solution: Show how to select even and odd elements using
:nth-child
.
17. JavaScript Closures
- Topic: What is a closure in JavaScript and how does it work?
- Solution: Show a basic closure example.
18. Custom Scrollbars in CSS
- Topic: How to create custom scrollbars with CSS?
- Solution: Demonstrate customizing scrollbar styles.
These topics are concise and important for improving core frontend development skills.
*************************************
1. What is the difference between ==
and ===
in JavaScript?
- Answer:
==
is the loose equality operator that compares values after type coercion, while===
is the strict equality operator that compares both the value and type.
2. What is the DOM (Document Object Model)?
- Answer: The DOM represents the page so that programs can manipulate the structure, style, and content of a document. It turns the HTML into a tree of nodes.
- Example: Using JavaScript to change content:
- Example: Using JavaScript to change content:
3. What is the difference between null
and undefined
in JavaScript?
- Answer:
undefined
means a variable has been declared but has not been assigned a value.null
is an assignment value, representing the intentional absence of any value.
4. What is the purpose of the this
keyword in JavaScript?
- Answer:
this
refers to the current context or object that is executing the code. It can vary depending on how a function is called.- Example: In a method:
- Example: In a method:
5. What are Promises in JavaScript?
- Answer: A Promise is an object representing the eventual completion or failure of an asynchronous operation. It has three states:
pending
,resolved
(fulfilled), orrejected
.- Example:
- Example:
6. What is localStorage
in JavaScript and how is it different from sessionStorage
?
- Answer:
localStorage
stores data with no expiration time, whilesessionStorage
only stores data for the duration of the page session (until the browser or tab is closed).
7. What is the box-sizing
property in CSS?
- Answer: The
box-sizing
property defines how the width and height of an element are calculated. Withbox-sizing: border-box;
, padding and border are included within the element's width and height.
8. What are CSS pseudo-classes and how are they used?
- Answer: Pseudo-classes are keywords that define the special state of an element (like
:hover
,:focus
,:nth-child
).- Example:
- Example:
9. What is the difference between a class
and an id
in HTML?
- Answer:
id
is a unique identifier for an element, meaning it should only appear once in a page.class
can be used to apply styles to multiple elements.
10. What is the event.preventDefault()
method in JavaScript?
- Answer: The
event.preventDefault()
method prevents the default action of an event (such as form submission or link redirection).- Example:
- Example:
11. What is the CSS position
property and its types?
- Answer: The
position
property defines how an element is positioned in a document. It can have values likestatic
,relative
,absolute
,fixed
, andsticky
.- Example:
- Example:
12. What is the purpose of the z-index
in CSS?
- Answer: The
z-index
property controls the stacking order of elements. Elements with a higherz-index
value appear above elements with a lower value.
13. What is the difference between inline and block elements in HTML?
- Answer: Inline elements take up only as much width as necessary (e.g.,
<span>
), while block elements take up the full width of their parent container (e.g.,<div>
,<p>
).
14. What is the this
keyword in arrow functions in JavaScript?
- Answer: In arrow functions,
this
is lexically bound to the context in which the function is defined, rather than dynamically bound (like in regular functions).
15. What are CSS pseudo-elements and how are they used?
- Answer: Pseudo-elements like
::before
and::after
are used to insert content before or after an element's actual content.
16. How to add custom fonts in CSS?
- Answer: You can add custom fonts using the
@font-face
rule or by using a service like Google Fonts.- Example (Google Fonts):
- Example (Google Fonts):
17. What is the async
and defer
attribute in script tags?
- Answer:
async
loads the script asynchronously whiledefer
ensures the script is executed after the document is parsed.
18. What is the difference between localStorage
and cookies
?
- Answer:
localStorage
is a larger, persistent storage option that does not expire, whereascookies
are smaller and can be set with an expiration date.
19. What is the difference between font-weight
and font-family
in CSS?
- Answer:
font-weight
defines the thickness of the text (e.g., normal, bold), whereasfont-family
specifies the typeface of the text (e.g., Arial, Times New Roman).
20. What is the fetch()
API in JavaScript?
- Answer: The
fetch()
API allows you to make network requests and handle responses asynchronously.
*******************************************
1. What is the Shadow DOM in Web Components?
- Answer: The Shadow DOM is a way to encapsulate the internal structure of a web component, isolating its styles and behavior from the rest of the document.
- Example:
- Example:
2. What is a CSS Flexbox wrap property?
- Answer: The
flex-wrap
property in Flexbox is used to control whether the flex items should wrap or not when there is not enough space in the container.- Example:
- Example:
3. What is the opacity
property in CSS?
- Answer: The
opacity
property controls the transparency of an element, where1
is fully opaque and0
is fully transparent.- Example:
- Example:
4. What is the isNaN()
function in JavaScript?
- Answer: The
isNaN()
function determines whether a value is NaN (Not-a-Number). It returnstrue
if the value is NaN, otherwisefalse
.- Example:
- Example:
5. What is the Event Bubbling
in JavaScript?
- Answer: Event bubbling is the process where events propagate from the target element to the root element, triggering event listeners on parent elements.
- Example:
- Example:
6. What is the defer
attribute in HTML scripts?
- Answer: The
defer
attribute tells the browser to continue parsing the HTML document while the script is being downloaded. The script is executed only after the document is fully parsed.- Example:
- Example:
7. What are Web APIs in JavaScript?
- Answer: Web APIs are interfaces provided by browsers that allow JavaScript to interact with the browser's features like local storage, geolocation, or fetch API for HTTP requests.
- Example: Fetching data using the Fetch API:
- Example: Fetching data using the Fetch API:
8. What are CSS Media Queries and how do they work?
- Answer: CSS Media Queries allow you to apply different styles based on the viewport size, screen resolution, or device orientation. It helps make websites responsive.
- Example:
- Example:
9. What is the visibility
property in CSS?
- Answer: The
visibility
property in CSS determines whether an element is visible or hidden, but unlikedisplay: none
, it still takes up space in the layout.- Example:
- Example:
10. What is the window.onload
event in JavaScript?
- Answer: The
window.onload
event is triggered when the entire page (including images, scripts, etc.) has finished loading.- Example:
- Example:
11. What is the DOMContentLoaded
event in JavaScript?
- Answer: The
DOMContentLoaded
event is triggered when the HTML document has been completely loaded and parsed, without waiting for stylesheets or images to load.- Example:
- Example:
12. What is the bubbling
and capturing
phases in JavaScript events?
- Answer: When an event is triggered, it goes through two phases:
capturing
(from root to target) andbubbling
(from target to root).- Example:
- Example:
13. What is the difference between var
, let
, and const
in JavaScript?
- Answer:
var
is function-scoped and can be re-declared.let
is block-scoped and cannot be re-declared in the same block.const
is block-scoped and cannot be reassigned after declaration.- Example:
- Example:
14. What is the JSON.parse()
and JSON.stringify()
in JavaScript?
- Answer:
JSON.parse()
converts a JSON string into a JavaScript object, whileJSON.stringify()
converts a JavaScript object into a JSON string.- Example:
- Example:
15. What are Web Workers in JavaScript?
- Answer: Web Workers allow JavaScript to run scripts in the background on a separate thread, without blocking the main thread (UI thread).
- Example:
- Example:
16. What is the purpose of event.stopPropagation()
?
- Answer: The
event.stopPropagation()
method stops the event from propagating (bubbling or capturing) to other elements.- Example:
- Example:
17. What is the CSS clip-path
property?
- Answer: The
clip-path
property allows you to define a specific region of an element to display, hiding parts outside the defined shape.- Example:
- Example:
18. What are Template Literals in JavaScript?
- Answer: Template literals allow embedding expressions inside strings using
${}
and support multi-line strings.- Example:
- Example:
19. What is the Array.prototype.map()
method in JavaScript?
- Answer: The
map()
method creates a new array by applying a function to each element in the original array.- Example:
- Example:
20. What is CORS (Cross-Origin Resource Sharing)?
- Answer: CORS is a security feature that allows or restricts web pages to make requests to domains other than the one from which the page was served.
- Example: If you're making an API call to a different domain, the server must allow it through CORS headers.
Comments
Post a Comment