Interview questions
Interview questions
Answer: A RESTful API is an architectural style that uses HTTP methods (GET, POST, PUT,
DELETE) to interact with resources. Each resource is identified by a URL, and data is typically
returned in JSON or XML format. REST APIs are stateless, meaning each request must contain
all the information needed to process it.
Answer:
● SQL Databases are relational (e.g., MySQL, PostgreSQL), and use tables and schemas
to store structured data. They are suitable for data with complex relationships and
transactions.
● NoSQL Databases (e.g., MongoDB, Cassandra) are non-relational, flexible in terms of
data structure, and are used for large-scale, unstructured, or semi-structured data.
Answer: OAuth 2.0 is an authorization framework that allows third-party applications to access
user data without exposing passwords. It involves authorization codes, access tokens, and
refresh tokens to enable secure access to resources.
Answer:
● GET is used to retrieve data from the server and should not have side effects.
● POST is used to send data to the server to create or update resources and may have
side effects.
Answer: Error handling can be done using status codes (e.g., 400 for bad request, 500 for
server errors) and custom error messages. In backend programming, exceptions should be
caught and handled appropriately, and logs should be maintained for debugging.
8. What are microservices, and how do they differ from monolithic architecture?
Answer:
● Microservices are small, independent services that work together. Each microservice is
responsible for a specific function and can be developed, deployed, and scaled
independently.
● Monolithic architecture refers to a single large application where all components are
tightly integrated and share a single database.
Answer: Middleware refers to software that sits between the client and server to process
requests and responses. It handles functions like authentication, logging, error handling, and
routing in web frameworks (e.g., Express in Node.js).
10. What is JWT (JSON Web Token)?
Answer: JWT is a compact, URL-safe means of representing claims between two parties. It is
often used in authentication mechanisms to pass claims securely between the client and server,
typically as part of an HTTP header.
Answer:
Answer: setState() is used to notify Flutter that the state of a widget has changed, causing
the widget to rebuild and update the UI.
Answer:
● Provider: A state management solution that makes it easy to manage app state and
share data.
● Riverpod: A more advanced version of Provider with better support for testability and
modularity.
● Bloc/Cubit: Uses streams to manage state and decouple UI from business logic.
● Redux: A predictable state container based on actions and reducers.
14. What is the difference between hot reload and hot restart in Flutter?
Answer:
● Hot reload: Quickly applies code changes without losing app state.
● Hot restart: Restarts the app, losing the current state but reflecting the latest code
changes.
15. What is a widget in Flutter, and what are the two main types of widgets?
Answer: A widget is the basic building block in Flutter's UI. There are two types:
Answer: The build() method is responsible for describing the part of the user interface
represented by the widget. It returns a widget tree, which is rendered on the screen.
17. What are keys in Flutter and why are they important?
Answer: Keys are used to preserve the state of widgets in Flutter, particularly when elements
are moved, added, or removed in the widget tree. They help identify a widget uniquely, which
helps in efficiently updating the UI.
Answer:
Answer: Flutter uses async and await to handle asynchronous operations. Functions that
perform asynchronous tasks are marked with async, and results are awaited using await.
20. What is the importance of the FutureBuilder widget in Flutter?
Answer: Flutter uses Skia, a 2D graphics library, as its rendering engine. Skia is fast because it
directly draws the UI on the screen rather than relying on platform-specific native views.
Answer: pubspec.yaml is used to manage dependencies, assets, and metadata for a Flutter
project. It defines the package version, dependencies, fonts, images, and more.
Answer:
● Root widget: The main entry point of the app (e.g., MaterialApp).
● Parent and child widgets: The hierarchy of widgets that define the UI layout.
Answer: StreamBuilder listens to a stream and rebuilds the UI based on the incoming data.
It's useful when data is continuously changing, such as with real-time data.
Answer: Dependencies in Flutter are managed using the pubspec.yaml file. You specify
package versions, and the flutter pub get command is used to fetch them.
30. How do you handle state in Flutter apps with multiple screens?
Answer: State can be managed globally using state management solutions like Provider,
Riverpod, or Bloc. The state can be passed down the widget tree via InheritedWidget or
ScopedModel.
Answer: Version control (e.g., Git) helps track changes to code over time, collaborate with other
developers, and manage different versions of an app.
32. What is an IDE, and which one do you use for Flutter development?
Answer: An IDE (Integrated Development Environment) is a software used to write, test, and
debug code. Popular IDEs for Flutter include Visual Studio Code and Android Studio.
Answer: Dependency injection is a design pattern used to implement Inversion of Control (IoC).
It involves passing dependencies to an object, rather than creating them inside the object,
improving testability and maintainability.
Answer:
● Synchronous: Operations are performed one after the other. The program waits for
each operation to complete before proceeding.
● Asynchronous: Operations are executed independently of the main program flow,
allowing other tasks to run while waiting for the operation to complete.
Answer: A RESTful endpoint is a specific URL that represents a resource, and it supports
HTTP methods (GET, POST, PUT, DELETE) to interact with the resource.
36. What are the advantages and disadvantages of using a cloud service like AWS or
Firebase?
Answer:
37. What are WebSockets, and how are they used in backend systems?
38. What are some best practices for writing clean and maintainable code?
Answer:
Answer: APIs can be tested using tools like Postman, Swagger, or writing automated tests
with frameworks like JUnit (for Java) or Mocha (for Node.js).
Answer: OAuth 2.0 is an authorization framework that allows third-party services to access user
resources without exposing passwords. It uses tokens for secure access.
Answer: A CDN helps deliver content (e.g., images, videos, scripts) quickly to users by caching
it on multiple geographically distributed servers.
Answer: The async keyword is used to define functions that return a Future and enable
asynchronous operations, allowing non-blocking code execution.
Answer: A CMS is a software application used to create, manage, and modify digital content.
Examples include WordPress, Joomla, and Drupal.
Answer:
Answer:
● 200: OK
● 400: Bad Request
● 401: Unauthorized
● 404: Not Found
● 500: Internal Server Error
Answer: Caching stores frequently accessed data in memory to reduce database load and
improve response times.
Answer: SSL/TLS encrypts data transmitted between a client and server, ensuring that
sensitive data (like passwords and credit card information) is secure during transmission.
These questions provide a comprehensive review of both backend and Flutter mobile
development topics that you might encounter in your interview. Best of luck with your
preparation!
Certainly! Here’s a list of 50 JavaScript interview questions with answers, covering basic to
advanced concepts:
1. What is JavaScript?
Answer:
Answer: JavaScript has 7 primitive data types: undefined, null, boolean, number,
bigint, string, and symbol.
Answer:
● undefined means a variable has been declared but has not been assigned a value.
● null is an assignment value that represents "no value" or "empty value."
Answer: A closure is a function that retains access to its lexical scope, even when the function
is executed outside that scope. Closures allow inner functions to access variables of their outer
functions.
Answer: Higher-order functions are functions that take other functions as arguments or return
functions as results. For example, map(), filter(), and reduce().
Answer: The this keyword refers to the context in which a function is called. It typically refers
to the object the function is a method of, but it can vary based on how the function is invoked
(e.g., in a method, alone, in an event handler).
Answer: Template literals are enclosed in backticks (`) and allow embedded expressions using
${expression}. They provide a more readable and concise way to create strings with
variables or expressions.
● ==: Checks for equality, but performs type coercion (e.g., 1 == '1' is true).
● ===: Checks for strict equality, without type coercion (e.g., 1 === '1' is false).
Answer: Event delegation is a technique where you attach a single event listener to a parent
element rather than multiple listeners to individual child elements. It uses event bubbling to
handle events on dynamically added elements.
Answer: Arrow functions are a shorter syntax for writing functions. They also do not have their
own this, so they inherit this from the surrounding context.
Answer:
Answer: Destructuring allows extracting values from arrays or objects and assigning them to
variables in a concise way. Example:
javascript
Copy code
const {name, age} = person;
17. What are the different types of loops in JavaScript?
Answer:
Answer: JavaScript uses an event loop to manage asynchronous code. It places functions that
are expected to run asynchronously (e.g., setTimeout, promises) in the message queue, and the
event loop executes them once the call stack is empty.
Answer:
Answer: A generator function is a function that can be paused and resumed using the yield
keyword. It returns an iterator that can produce values on demand.
Answer:
● WeakMap: A collection of key-value pairs where keys are objects and values can be any
type. The keys are weakly referenced, meaning they don’t prevent garbage collection.
● WeakSet: A collection of unique objects with weak references.
23. What is the difference between a shallow copy and a deep copy in JavaScript?
Answer:
● Shallow copy: Copies the references of nested objects. Changes to nested objects in
the copy will affect the original.
● Deep copy: Creates a complete, independent copy, including all nested objects.
Changes to the copy do not affect the original.
Answer: A Symbol is a primitive data type that represents a unique and immutable value. It is
often used to create unique property keys.
Answer: async/await is a syntax for handling asynchronous code. async makes a function
return a promise, and await is used inside async functions to wait for the promise to resolve.
Answer: JavaScript has function-level scoping. A closure allows a function to retain access to
its lexical scope even after the function has executed, which can be used for private variables
and callbacks.
Answer: eval() is a function that executes a string of JavaScript code. It is generally avoided
due to security risks and performance issues.
Answer:
● Promise.all(): Resolves when all promises are resolved or rejects if any promise is
rejected.
● Promise.race() resolves or rejects as soon as the first promise resolves or rejects.
Answer:
● localStorage: Stores data with no expiration time, even when the browser is closed.
● sessionStorage: Stores data for the duration of the page session (until the tab is
closed).
Answer: The window object represents the global context in the browser. It contains properties,
methods, and events associated with the browser window, like window.location,
window.alert(), etc.
Answer:
● undefined: A variable has been declared but not assigned any value.
● undeclared: A variable has not been declared at all.
Answer: The DOMContentLoaded event is fired when the initial HTML document has been
completely loaded and parsed, without waiting for stylesheets, images, or subframes to finish
loading.
Answer:
Answer:
Answer: Memoization is an optimization technique where results of expensive function calls are
stored, and subsequent calls with the same arguments return the cached result instead of
re-executing the function.
Answer: JavaScript provides try...catch for synchronous error handling and .catch() for
handling rejected promises in asynchronous code.
Answer: The forEach() method iterates over elements in an array, executing a provided
callback function for each element.
Advanced Topics
Answer: Both call and apply invoke a function with a specified this context and arguments,
but:
Answer: The new keyword is used to create an instance of an object that is defined by a
constructor function or class.
Answer: Node.js uses an event-driven, non-blocking I/O model, and the event loop allows
Node.js to handle multiple operations concurrently without blocking the execution thread.
Answer:
● Synchronous: Executes line by line, blocking further code execution until the current
function completes.
● Asynchronous: Executes in the background, allowing other code to run while waiting for
completion.
Answer: setTimeout executes a function after a specified delay once, while setInterval
executes a function repeatedly at the specified interval.
Answer: Event delegation is a technique where you attach a single event listener to a parent
element rather than to multiple child elements. The event listener relies on event propagation
(bubbling) to handle events on child elements.
Answer: JavaScript Modules allow you to split code into smaller, reusable units. It can export
functions or variables from one module and import them into another using import and
export keywords.
javascript
Copy code
class Person {
constructor(name) {
this.name = name;
}
}
Answer: Both are used to store data on the client's browser. localStorage persists data
across sessions, while sessionStorage stores data only for the duration of the page session.
Answer: You can use the event.preventDefault() method to stop the default behavior of
an event (e.g., preventing a form from submitting).