Interview Questions

Front-End

What is HTML?

HTML (HyperText Markup Language) is the standard language used to create web pages. It defines the structure and layout of a webpage using a series of elements and tags.

What are HTML tags and attributes?

HTML tags are the building blocks of an HTML document, enclosed in angle brackets like <p>. Attributes provide additional information about an element, such as id, class, or src.

What is the difference between HTML and XHTML?

HTML is a markup language that is more forgiving with syntax, while XHTML is stricter, adhering to XML rules such as proper nesting and case sensitivity.

What is the purpose of the <!DOCTYPE> declaration?

The <!DOCTYPE> declaration specifies the HTML version used in the document and ensures that browsers render the page correctly.

What are self-closing tags? Give examples.

Self-closing tags are HTML elements that do not require a closing tag. Examples include <img />, <br />, and <input />.

What is the <meta> tag used for?

The <meta> tag provides metadata about an HTML document, such as character set, description, and keywords for SEO. Example: <meta charset="UTF-8">.

What is the difference between id and class attributes?

The id attribute uniquely identifies an element, while the class attribute groups multiple elements for styling or scripting.

What is the difference between <ol>, <ul>, and <dl>?

<ol>: Ordered list with numbers or letters.
<ul>: Unordered list with bullets.
<dl>: Definition list for terms and their descriptions.

What is the <iframe> tag used for?

The <iframe> tag embeds another HTML document within the current document. Example:


        
What are semantic HTML tags? Why are they important?

Semantic HTML tags clearly describe their meaning in a human- and machine-readable way. Examples include <header>, <footer>, and <article>. They improve accessibility and SEO.

What is CSS, and why is it used?

CSS (Cascading Style Sheets) is used to style HTML elements by defining their layout, colors, fonts, and overall presentation. It separates content from design.

What are the different types of CSS?

CSS can be applied in three ways:
Inline CSS: Written within the HTML element using the style attribute.
Internal CSS: Defined within a <style> tag in the document's <head>.
External CSS: Linked as an external file using the <link> tag.

What is the DOM?

The DOM (Document Object Model) is a programming interface for HTML and XML documents. It represents the structure of a document as a tree of objects that can be manipulated with JavaScript.

What is the difference between inline, block, and inline-block elements?

Inline: Does not start on a new line and only takes up as much width as necessary (e.g., <span>).
Block: Starts on a new line and takes up the full width (e.g., <div>).
Inline-block: Behaves like inline elements but allows setting width and height.

What is responsive design?

Responsive design ensures a website adapts to various screen sizes and resolutions using techniques like fluid grids, flexible images, and CSS media queries.

What are CSS media queries?

CSS media queries allow you to apply styles based on the device's screen size, orientation, resolution, and other properties. Example:

    @media (max-width: 768px) {
        body {
            background-color: lightblue;
        }
    }
        
What is JavaScript, and why is it important in web development?

JavaScript is a programming language that adds interactivity to web pages, enabling dynamic content, animations, and user interactions like form validation.

What is the difference between var, let, and const in JavaScript?

var: Function-scoped and can be re-declared.
let: Block-scoped and cannot be re-declared within the same scope.
const: Block-scoped and must be initialized at the time of declaration; its value cannot be reassigned.

What is the purpose of JavaScript frameworks like React or Angular?

JavaScript frameworks simplify building dynamic, feature-rich web applications by providing reusable components, efficient state management, and tools for handling user interfaces and routing.

What are the differences between GET and POST methods in HTTP?

GET: Retrieves data from a server; parameters are included in the URL.
POST: Submits data to a server for processing; parameters are sent in the request body.

Back-End

What is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language designed for web development, used to create dynamic and interactive web pages.

What are PHP variables, and how are they declared?

PHP variables are used to store data. They start with a dollar sign ($) followed by the variable name. Example:

$variableName = "Hello, World!";
        
What is the difference between include() and require() in PHP?

Both functions are used to include files in a PHP script, but:
include(): Produces a warning if the file is missing and continues execution.
require(): Produces a fatal error and stops execution if the file is missing.

What is Python, and why is it used in web development?

Python is a versatile programming language widely used in web development for creating web applications, handling server-side logic, and working with frameworks like Django and Flask.

What are Python decorators?

Python decorators are functions that modify the behavior of another function or method. They are often used for logging, authentication, and other cross-cutting concerns.

What is Django?

Django is a high-level Python web framework that simplifies building secure and scalable web applications by providing tools for ORM, templating, routing, and authentication.

What is MySQL?

MySQL is an open-source relational database management system (RDBMS) that uses Structured Query Language (SQL) for accessing and managing data.

What is the difference between SQL and MySQL?

SQL: A language for querying and managing databases.
MySQL: A specific RDBMS that implements SQL.

What is the difference between primary key and foreign key in MySQL?

Primary Key: Uniquely identifies a row in a table.
Foreign Key: References the primary key of another table to establish a relationship between tables.

What is an ORM in the context of backend development?

ORM (Object-Relational Mapping) is a technique for interacting with a database using objects in programming languages instead of raw SQL. Examples include SQLAlchemy (Python) and Eloquent (PHP).

What is session management in PHP?

Session management is a way to persist user data across multiple requests. In PHP, sessions are managed using session_start() and $_SESSION.

What is the purpose of the "virtual environment" in Python?

Virtual environments in Python isolate dependencies for a project, ensuring that packages installed for one project don’t interfere with others.

How do you connect to a MySQL database in PHP?

Using the mysqli_connect() function or PDO (PHP Data Objects). Example with mysqli:

$conn = mysqli_connect("localhost", "username", "password", "database");

Data Science

What is Data Science?

Data Science is an interdisciplinary field that combines statistics, programming, and domain expertise to extract meaningful insights from data.

What is the difference between supervised and unsupervised learning?

Supervised Learning: Involves labeled data for training, where input-output pairs are known.
Unsupervised Learning: Involves unlabeled data and aims to find patterns or clusters without predefined outputs.

What is overfitting in machine learning, and how can it be prevented?

Overfitting occurs when a model performs well on training data but poorly on unseen data. It can be prevented using:
- Cross-validation
- Regularization techniques (e.g., L1/L2 penalties)
- Reducing model complexity
- Increasing training data.

What is the difference between classification and regression?

Classification: Predicts discrete labels or categories.
Regression: Predicts continuous numerical values.

What is feature engineering?

Feature engineering is the process of selecting, transforming, or creating features (variables) to improve a model's performance.

What are the steps of a typical data science project?

1. Define the problem
2. Collect data
3. Clean and preprocess data
4. Perform exploratory data analysis (EDA)
5. Feature engineering
6. Model selection and training
7. Model evaluation and tuning
8. Deploy and monitor the model.

What is a confusion matrix?

A confusion matrix is a table used to evaluate the performance of a classification model by comparing predicted vs. actual outcomes. It includes:
- True Positives (TP)
- True Negatives (TN)
- False Positives (FP)
- False Negatives (FN).

What is cross-validation?

Cross-validation is a technique to evaluate the performance of a model by splitting the data into training and testing subsets multiple times. Common methods include K-Fold and Leave-One-Out cross-validation.

What is the difference between bagging and boosting?

Bagging: Combines predictions from multiple models trained independently to reduce variance (e.g., Random Forest).
Boosting: Sequentially trains models to correct errors made by previous models, reducing bias (e.g., Gradient Boosting).

What is dimensionality reduction?

Dimensionality reduction is the process of reducing the number of features or variables in a dataset to improve efficiency and reduce noise. Techniques include PCA and t-SNE.

What are outliers, and how can they be treated?

Outliers are data points significantly different from the rest of the dataset. They can be treated by:
- Removing them
- Transforming the data (e.g., log transformation)
- Using robust models that are less sensitive to outliers.

What is the bias-variance tradeoff?

The bias-variance tradeoff is a fundamental issue in machine learning:
- High bias: Model underfits the data.
- High variance: Model overfits the data.
The goal is to find the optimal balance to minimize total error.

What is the difference between deep learning and traditional machine learning?

Deep Learning: Uses neural networks with multiple layers to learn features and patterns directly from raw data.
Traditional Machine Learning: Requires manual feature engineering and uses algorithms like SVM, Random Forest, etc.

What are some commonly used libraries in Python for Data Science?

- NumPy: Numerical computations
- Pandas: Data manipulation and analysis
- Matplotlib/Seaborn: Data visualization
- Scikit-learn: Machine learning
- TensorFlow/PyTorch: Deep learning.

Python

What is Python?

Python is a high-level, interpreted, and general-purpose programming language known for its readability and versatility. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming.

What are Python's key features?

- Easy to read and write
- Dynamically typed
- Interpreted language
- Extensive standard library
- Supports multiple programming paradigms
- Platform-independent.

What are Python's data types?

Common data types in Python include:
- Numeric: int, float, complex
- Sequence: list, tuple, range
- Text: str
- Set: set, frozenset
- Mapping: dict
- Boolean: bool
- NoneType: None.

What are Python's conditional statements?

Conditional statements in Python include:
- if: Executes a block of code if the condition is true.
- elif: Adds additional conditions.
- else: Executes if no conditions are true.
Example:

if x > 0:
    print("Positive")
elif x < 0:
    print("Negative")
else:
    print("Zero")
            

What are Python's loops, and how are they used?

- for: Iterates over a sequence (e.g., list, tuple, range).
- while: Executes as long as a condition is true.
Example:

# for loop
for i in range(5):
    print(i)

# while loop
count = 0
while count < 5:
    print(count)
    count += 1
            

What is the difference between a list and a tuple in Python?

- List: Mutable, can be modified after creation, defined using square brackets [].
- Tuple: Immutable, cannot be modified after creation, defined using parentheses ().

What is a Python dictionary?

A dictionary is a collection of key-value pairs, where keys are unique and values can be any data type. It is defined using curly braces {}. Example:

my_dict = {"name": "Alice", "age": 25}
print(my_dict["name"])  # Output: Alice
        
What are Python's functions, and how are they defined?

Functions are reusable blocks of code that perform specific tasks. They are defined using the def keyword.
Example:

def greet(name):
    return f"Hello, {name}!"

print(greet("Alice"))  # Output: Hello, Alice!
            

What is the difference between *args and **kwargs?

- *args: Used to pass a variable number of positional arguments to a function.
- **kwargs: Used to pass a variable number of keyword arguments to a function.
Example:

def example_function(*args, **kwargs):
    print(args)
    print(kwargs)

example_function(1, 2, 3, name="Alice", age=25)
# Output:
# (1, 2, 3)
# {'name': 'Alice', 'age': 25}
            

What are Python's modules and packages?

- Module: A single Python file containing code (functions, classes, etc.) that can be imported.
- Package: A collection of modules organized in directories with an __init__.py file.
Example:

# Importing a module
import math
print(math.sqrt(16))  # Output: 4.0
            

What is Python's Global Interpreter Lock (GIL)?

The Global Interpreter Lock (GIL) is a mutex that protects access to Python objects, ensuring that only one thread executes Python bytecode at a time, even on multi-core processors. This simplifies memory management but limits multi-threaded performance in CPU-bound tasks.

What are Python's file handling operations?

Python provides functions for file handling, such as reading and writing files:
- open(): Opens a file.
- read(): Reads file content.
- write(): Writes to a file.
Example:

# Writing to a file
with open("example.txt", "w") as f:
    f.write("Hello, World!")

# Reading from a file
with open("example.txt", "r") as f:
    print(f.read())  # Output: Hello, World!
            

What are Python decorators?

Decorators are functions that modify the behavior of another function or method. They are often used for logging, authentication, or timing. Example:

def decorator(func):
    def wrapper():
        print("Before the function call")
        func()
        print("After the function call")
    return wrapper

@decorator
def say_hello():
    print("Hello!")

say_hello()
# Output:
# Before the function call
# Hello!
# After the function call