Elixir & Phoenix Interview Questions Hindi mein

Elixir & Phoenix कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Getting Started with Elixir

1. What does Elixir gain by running on the BEAM?

  1. Lightweight isolated processes, message passing, fault tolerance and distribution
  2. Manual memory management
  3. Static typing like Java
  4. Access to the JVM ecosystem
जवाब देखें

जवाब: Lightweight isolated processes, message passing, fault tolerance and distribution

The Erlang VM provides cheap processes, supervision and distribution.

पाठ: What Elixir Is and Why the BEAM Matters

2. What does `mix new shop --sup` add compared with plain `mix new shop`?

  1. A web server
  2. A database
  3. Static types
  4. An application module with a supervision tree
जवाब देखें

जवाब: An application module with a supervision tree

The --sup flag generates an Application that starts a supervisor.

पाठ: Installing Elixir: IEx, Mix and Hex

3. What does `%{order | total: 1500}` do?

  1. Mutates order in place
  2. Adds a new key only
  3. Returns a new map with total updated, raising if total is not already a key
  4. Deletes the total key
जवाब देखें

जवाब: Returns a new map with total updated, raising if total is not already a key

The update syntax creates a new map and requires the key to exist.

पाठ: Basic Types and Immutability

Pattern Matching, Functions and Pipelines

4. What does the pin operator ^ do in a pattern?

  1. Rebinds the variable
  2. Makes the variable global
  3. Matches against the variable's existing value instead of rebinding it
  4. Ignores the value
जवाब देखें

जवाब: Matches against the variable's existing value instead of rebinding it

Pinned variables are compared, not rebound.

पाठ: The Match Operator and Pattern Matching

5. In Elixir, how are total/1 and total/2 related?

  1. They are the same function
  2. They are different functions because arity is part of a function's identity
  3. total/2 overrides total/1
  4. Defining both is an error
जवाब देखें

जवाब: They are different functions because arity is part of a function's identity

Functions are identified by name and arity.

पाठ: Modules, Functions and Guards

6. Where does |> place the value from the left side?

  1. As the first argument of the function on the right
  2. As the last argument
  3. In a global variable
  4. It replaces all arguments
जवाब देखें

जवाब: As the first argument of the function on the right

The pipe inserts the value as the first argument.

पाठ: The Pipe Operator, Enum and Stream

Control Flow, Structs and Errors

7. What happens when a clause inside with does not match?

  1. with stops and returns the non-matching value, or passes it to the else block
  2. The program crashes always
  3. The clause is skipped and the next one runs
  4. It retries the clause
जवाब देखें

जवाब: with stops and returns the non-matching value, or passes it to the else block

with short-circuits on the first non-matching value.

पाठ: case, cond, if and with

8. What is the difference between a protocol and a behaviour?

  1. They are identical
  2. Behaviours dispatch on data types
  3. Protocols only work with strings
  4. Protocols dispatch on the data type of a value; behaviours define functions a module must implement
जवाब देखें

जवाब: Protocols dispatch on the data type of a value; behaviours define functions a module must implement

Protocols give data-type polymorphism; behaviours are module contracts.

पाठ: Structs, Protocols and Behaviours

9. What does a bang function such as File.read!/1 do on failure?

  1. Returns {:error, reason}
  2. Returns nil
  3. Raises an exception
  4. Retries forever
जवाब देखें

जवाब: Raises an exception

Bang functions return the plain value or raise.

पाठ: Errors: Tagged Tuples, Exceptions and Bang Functions

Processes and OTP

10. How do BEAM processes share data?

  1. Through shared memory and locks
  2. Through global variables
  3. They do not share memory; they communicate by copying messages into mailboxes
  4. Through files only
जवाब देखें

जवाब: They do not share memory; they communicate by copying messages into mailboxes

Isolation plus message passing eliminates data races.

पाठ: Processes and Message Passing

11. Which GenServer callback handles synchronous requests made with GenServer.call?

  1. handle_cast/2
  2. handle_call/3
  3. handle_info/2
  4. init/1
जवाब देखें

जवाब: handle_call/3

handle_call replies to the caller, which waits up to a timeout.

पाठ: GenServer: Stateful Servers

12. With the :one_for_one strategy, what happens when a child crashes?

  1. Only the crashed child is restarted
  2. All children restart
  3. The whole application stops
  4. Nothing happens
जवाब देखें

जवाब: Only the crashed child is restarted

one_for_one restarts just the failed child.

पाठ: Supervisors and Fault Tolerance

Tasks, ETS and Metaprogramming

13. What does max_concurrency in Task.async_stream control?

  1. How many items are processed concurrently at once
  2. The total number of items
  3. The number of CPU cores
  4. The retry count
जवाब देखें

जवाब: How many items are processed concurrently at once

It bounds the number of tasks running at the same time.

पाठ: Tasks and Concurrent Work

14. Why is ETS often faster than a GenServer for read-heavy caches?

  1. It stores data on disk
  2. It compresses data
  3. It is written in JavaScript
  4. Many processes can read ETS concurrently without sending messages through a single process
जवाब देखें

जवाब: Many processes can read ETS concurrently without sending messages through a single process

ETS lookups avoid the serialisation of a single server process.

पाठ: ETS, Agents and Shared State

15. What does `use Shop.Auditable, entity: "invoice"` do?

  1. Imports a module at run time
  2. Creates a process
  3. Calls Shop.Auditable.__using__/1 at compile time, which injects code into the calling module
  4. Installs a dependency
जवाब देखें

जवाब: Calls Shop.Auditable.__using__/1 at compile time, which injects code into the calling module

use invokes the __using__ macro, which returns code to inject.

पाठ: Macros and Metaprogramming

Phoenix and Ecto

16. What is a plug in Phoenix?

  1. A database adapter
  2. A CSS framework
  3. A function or module that receives a Plug.Conn and returns a (possibly modified) conn
  4. A type of process
जवाब देखें

जवाब: A function or module that receives a Plug.Conn and returns a (possibly modified) conn

Plugs form the composable request pipeline.

पाठ: Phoenix Fundamentals

17. What is the main job of an Ecto changeset?

  1. To open database connections
  2. To cast and validate external data and track changes and errors before persisting
  3. To render HTML
  4. To start processes
जवाब देखें

जवाब: To cast and validate external data and track changes and errors before persisting

Changesets filter, cast and validate data, collecting errors.

पाठ: Ecto: Schemas, Changesets and Queries

18. What does action_fallback do in a Phoenix controller?

  1. Sends non-conn return values such as {:error, ...} to a fallback controller that renders the response
  2. Retries the action
  3. Caches responses
  4. Disables CSRF
जवाब देखें

जवाब: Sends non-conn return values such as {:error, ...} to a fallback controller that renders the response

It centralises error rendering for actions that return error tuples.

पाठ: Contexts, JSON APIs and Authentication

Real-Time Features and Testing

19. After the initial render, what does LiveView send to the browser when state changes?

  1. A minimal diff of the changed parts of the HTML over a WebSocket
  2. A full page reload
  3. A JSON API response that the client renders
  4. Nothing
जवाब देखें

जवाब: A minimal diff of the changed parts of the HTML over a WebSocket

LiveView tracks changes and sends compact diffs.

पाठ: Phoenix LiveView

20. What does Phoenix.PubSub let processes do?

  1. Share memory
  2. Run SQL queries
  3. Compile templates
  4. Subscribe to topics and receive messages broadcast to them, even across cluster nodes
जवाब देखें

जवाब: Subscribe to topics and receive messages broadcast to them, even across cluster nodes

PubSub decouples publishers from subscribers across nodes.

पाठ: Channels, PubSub and Presence

21. What does assert_receive check?

  1. That a function returns true
  2. That a file exists
  3. That the test process receives a matching message within a timeout
  4. That a test is async
जवाब देखें

जवाब: That the test process receives a matching message within a timeout

assert_receive waits for a message matching a pattern.

पाठ: Testing with ExUnit

Deployment, Quality, Idioms and Revision

22. Where should secrets such as DATABASE_URL be read in a release?

  1. config/config.exs
  2. mix.exs
  3. config/runtime.exs, evaluated when the release starts
  4. Hard-coded in a module
जवाब देखें

जवाब: config/runtime.exs, evaluated when the release starts

runtime.exs runs at boot, so each environment can supply its own values.

पाठ: Releases, Configuration and Deployment

23. What does Dialyzer use to find bugs?

  1. Runtime logs
  2. Typespecs and success typing to detect provable type inconsistencies
  3. Unit tests
  4. Code formatting rules
जवाब देखें

जवाब: Typespecs and success typing to detect provable type inconsistencies

Dialyzer analyses types statically and reports definite contradictions.

पाठ: Code Quality: Formatter, Credo, Dialyzer and Types

24. Why is String.to_atom on user input dangerous?

  1. Atoms are not garbage-collected, so attackers can exhaust the atom table and crash the VM
  2. It is slow
  3. It returns nil
  4. It only works for numbers
जवाब देखें

जवाब: Atoms are not garbage-collected, so attackers can exhaust the atom table and crash the VM

The atom table has a limit and atoms are never freed.

पाठ: Idiomatic Elixir and Common Pitfalls

25. Which construct restarts crashed processes in an Elixir application?

  1. A protocol
  2. A changeset
  3. A plug
  4. A supervisor
जवाब देखें

जवाब: A supervisor

Supervisors monitor children and restart them according to their strategy.

पाठ: Revision and Interview Questions

← कोर्स पर वापस जाएँ