What is Git and GitHub?
Git: Git is a tool used by software developers to manage and keep track of changes in their code.
Imagine you're writing a book with friends, and everyone is making changes at the same time. It
would be chaos without some way to manage who is changing what and when. Git helps with
this by allowing multiple people to work on the same project without overwriting each other's
work. It keeps a record of every change made, so if something goes wrong, you can easily go
back to an earlier version.
GitHub: GitHub is like a social network for developers that hosts Git repositories. Think of it as
a place where developers can store their code online, collaborate with others, track issues (like
bugs or feature requests), and manage their projects. GitHub adds a web interface to Git, making
it easier to see what's going on with the project, discuss changes, and organize work.
Difference between Git and GitHub
Git is the actual version control system—it's the tool that tracks changes in your code. GitHub is
a service that hosts your Git repositories online, adding features like a web interface, issue
tracking, and collaboration tools. In short, Git is the engine, and GitHub is the car that makes it
easier to drive.
Alternatives to GitHub
Some other platforms that offer similar services to GitHub are:
GitLab: Another platform for hosting Git repositories with features for issue tracking,
CI/CD, and more.
Bitbucket: A platform by Atlassian for Git repository hosting with strong integration
with other Atlassian tools.
SourceForge: One of the oldest platforms for hosting open-source projects.
What are cookies and sessions? Explain their difference.
Cookies: Cookies are small pieces of data that websites store on your computer to remember
information about you. For example, if you log into a website, it can use a cookie to remember
you're logged in, so you don't have to log in again on every page.
Sessions: Sessions are similar but work differently. When you visit a website, the server creates
a session to store information about your visit. This information is kept on the server and linked
to your session ID, which is often stored in a cookie on your browser. When you do something
on the website, like adding items to a shopping cart, the server uses your session to keep track of
those items.
Difference:
Cookies are stored on the client (your browser).
Sessions are stored on the server.
What is ReactJS and what happens when you change a state? Is it a library or
framework?
ReactJS: ReactJS is a JavaScript library (although sometimes called a framework) used to build
user interfaces, particularly for single-page applications where you need a dynamic, responsive
experience.
Changing State in React: When you change the state in a React component (state is like the
component’s memory), React updates the component and any of its child components to reflect
the new state. This means the user interface will automatically update to show the latest
information.
Library or Framework: React is a library because it focuses on building user interfaces and
leaves the rest of the application structure up to the developer. However, because it has a large
ecosystem and often dictates how you structure parts of your app, it's sometimes considered a
framework.
What are components in ReactJS?
Components: Components in React are like building blocks of a user interface. Each component
is a self-contained piece of the UI that can manage its own state and behavior. Think of them as
custom HTML elements that you can use to build complex user interfaces by combining them in
different ways.
What is virtual DOM in React?
Virtual DOM: The virtual DOM is a lightweight, in-memory representation of the real DOM
(the structure of the web page). When you change something in a React component, React
updates the virtual DOM first. It then compares the virtual DOM with the real DOM (a process
called "reconciliation") and only makes the necessary changes to the real DOM. This makes
updates faster and more efficient.
What is JSX? How is JSX parsed into JavaScript?
JSX: JSX (JavaScript XML) is a syntax extension for JavaScript that looks similar to HTML. It
allows you to write HTML-like code within JavaScript, which React uses to describe what the UI
should look like.
Parsing JSX: Tools like Babel convert JSX into regular JavaScript. For example, <div>Hello,
World!</div> in JSX is turned into React.createElement('div', null, 'Hello,
World!') in JavaScript.
What is the use of Webpack?
Webpack: Webpack is a tool that bundles your JavaScript and other assets (like CSS, images)
into a single file (or multiple files) that can be loaded by the browser. It also handles
dependencies between your modules, making it easier to manage complex web applications.
Suppose a website is very fast and I'm willing to make it slow. What actions
could be taken?
To intentionally slow down a website, you could:
Introduce server-side delays.
Increase the size of images and scripts.
Add unnecessary scripts or libraries.
Reduce server processing power or bandwidth.
What is CDN? How does CDN work?
CDN (Content Delivery Network): A CDN is a network of servers distributed across different
locations. When a user requests content (like a webpage), the CDN serves it from the nearest
server, reducing the time it takes to load and improving performance. CDNs cache content at
multiple locations worldwide to ensure faster delivery and better availability.
What is Indexing in Database? Do Indexing affect only fetching or will it affect
insertion and updating as well?
Indexing: Indexing is a way to organize data in a database to make it faster to retrieve. Think of
it like an index in a book that helps you quickly find the page you need.
Effects on Operations:
Fetching: Indexes significantly speed up data retrieval.
Insertion and Updating: Indexes can slow down insertion and updating because the
database has to update the index every time the data changes.
How will you move a commit from one branch to another branch?
To move a commit from one branch to another in Git, you can use the git cherry-pick
command. This command takes the changes from a specific commit and applies them to another
branch.
Example:
bash
Copy code
git checkout target-branch
git cherry-pick <commit-hash>
What does git stash command do?
The git stash command temporarily saves your changes in the working directory so you can
work on something else without committing those changes. Later, you can retrieve (or "unstash")
those changes and continue working on them.
Which website will be faster: one built with JavaScript or one built with React?
Both JavaScript and React can be used to build fast websites. React is built on JavaScript, so it's
not about choosing one over the other but rather how you use them. The speed of a website
depends on how well the code is optimized, server performance, network latency, and other
factors, not just the technology used.
What actions could be taken to make a website faster?
To make a website faster, you can:
Optimize images and other assets.
Minify and concatenate CSS and JavaScript files.
Enable compression (like gzip).
Leverage browser caching.
Use a CDN (Content Delivery Network).
Reduce server response time.
Optimize database queries.
Implement lazy loading of resources.
Where is session data stored on backend servers?
Session data is typically stored on the server. This can be in-memory storage, a database, or a
dedicated session storage system. For small applications, in-memory storage is common, while
larger applications might use a database or a specialized session store for scalability and
persistence.
Git stores all the data in which folder?
Git stores all its data in a directory called .git at the root of the repository. This directory
contains all the information necessary for version control, including metadata, object database,
configuration files, and references to commits.
How does the .gitignore file work?
The .gitignore file specifies files and directories that Git should ignore. When you add files to
a repository, Git checks the .gitignore file and ignores any files or directories that match the
specified patterns. This is useful for excluding files that shouldn't be tracked, like build artifacts
or temporary files.
How to verify an email? Which is the best method: client-based or server-based?
Email Verification: Typically, email verification involves sending an email with a verification
link to the provided email address. The user must click the link to confirm their email address.
Best Method: Server-based email verification is more secure because it verifies the email
address directly with the email server, whereas client-based verification relies on user input and
can be manipulated.
Will a session work if we decline cookies?
Sessions can still work without cookies, but the session ID must be passed through other means,
like URL rewriting or hidden form fields. However, declining cookies may impact the usability
and functionality of some websites that rely heavily on cookies for session management.
Why do sessions get destroyed when reopening a website after closing it?
Sessions typically expire after a period of inactivity to free up server resources. When you close
a website and reopen it later, the server may no longer recognize your session ID, so you're
treated as a new visitor and might need to log in again.
What is GitHub's cherry-pick command?
The git cherry-pick command in Git allows you to apply the changes from a specific commit
to another branch without merging the entire branch. This is useful for picking just the changes
you need.
What is DOM?
DOM (Document Object Model): The DOM is a programming interface for web documents. It
represents the structure of a document as a tree of objects. Each part of the document (like
elements, attributes, and text) is represented as a node in the tree. The DOM allows programs to
dynamically access and manipulate the content, structure, and style of web documents.
What is encryption and decryption? What is hashing? What is the purpose of
salting?
Encryption: Encryption is the process of converting plain text into cipher text using an
algorithm and a key, so that it can only be read by someone who has the key.
Decryption: Decryption is the reverse process, converting cipher text back into plain text using
the same algorithm and key.
Hashing: Hashing is the process of converting data into a fixed-size string of characters using a
hashing algorithm. Hashing is commonly used for storing passwords securely.
Salting: Salting involves adding random data to the input of a hashing function to ensure that
even if two inputs are the same, their hash values will be different. This prevents attackers from
using precomputed hash tables (rainbow tables) to crack passwords.
How does JWT work? How do symmetric and asymmetric algorithms work?
JWT (JSON Web Token): JWT is a compact, URL-safe means of representing claims to be
transferred between two parties. It’s commonly used for authentication and information
exchange. A JWT consists of three parts: header, payload, and signature. When a server
generates a JWT, it signs it using a secret key or a public/private key pair.
Symmetric Algorithms: Symmetric algorithms use the same key for both encryption and
decryption. This means both parties must have the same key, which must be kept secret.
Asymmetric Algorithms: Asymmetric algorithms use a pair of keys: one for encryption and one
for decryption. The public key can be shared with anyone, but the private key must be kept
secret. This allows secure communication even if the public key is widely known.
Do all hashing algorithms generate hash values of fixed-size strings of
characters?
Most hashing algorithms generate hash values of fixed size, regardless of the input size. For
example, SHA-256 always produces a 256-bit hash value. However, some hashing algorithms
can produce variable-length hash values, but these are less common in practice.
Can two computers have the same public IP?
Yes, two or more computers can share the same public IP address if they are part of the same
network and behind a router or firewall using Network Address Translation (NAT). NAT maps
multiple private IP addresses to a single public IP address.
How does a router assign IP addresses to computers? What happens when you
hit a URL while connected to a router?
IP Assignment: A router typically assigns IP addresses to computers on a local network using
DHCP (Dynamic Host Configuration Protocol). When a device connects to the network, the
router assigns it an available IP address from a pool of addresses.
Hitting a URL: When you hit a URL, your device sends a request to the router, which forwards
it to the appropriate destination server on the internet. The server processes the request and sends
the response back to the router, which then forwards it to your device.
What if two computers connected to the same router are assigned the same IP
address?
If two computers on the same network are assigned the same IP address, it can cause network
conflicts and communication issues. Typically, a DHCP server prevents this by ensuring each
device gets a unique IP address.
How would you implement a YouTube-like automatic video quality controller
without using any JavaScript library?
To implement an automatic video quality controller:
Use the HTML5 <video> element with attributes like preload and autoplay.
Use CSS media queries to detect screen size and adjust video quality.
You could write custom JavaScript to monitor network conditions and adjust the video
source accordingly.
How would you implement an OTP verification tool without using a backend?
To implement OTP verification without a backend, you could:
Use client-side JavaScript to generate a random OTP.
Use a third-party service like Twilio to send the OTP via SMS.
Prompt the user to enter the OTP received.
Verify the entered OTP with the generated OTP on the client side.
How would an elevator work with a person on the 6th floor and another person
on the 10th floor? What algorithm and data structure could be used?
To manage an elevator system:
Use a priority queue data structure to manage the floor requests.
Implement an algorithm that prioritizes stops based on the direction of travel to minimize
travel time and optimize efficiency.
For example, if the elevator is going up, it will pick up passengers on floors above and
drop them off before changing direction.