Home > Web Front-end > JS Tutorial > DEV Interview Questions

DEV Interview Questions

DDD
Release: 2025-01-05 13:46:45
Original
473 people have browsed it

Perguntas de entrevista DEV

Here is a list of programming questions, with explanatory answers and additional examples for each:

1. What is the purpose of transactions in SQL?

Answer:

Ensure the integrity of data stored in the database.

Explanation:

SQL transactions ensure that operations performed on the database are consistent and secure. They follow the ACID principles (Atomicity, Consistency, Isolation and Durability), ensuring that either all operations in a transaction are carried out or none of them. If a failure occurs, the transaction can be rolled back, maintaining data integrity.

Example:

Imagine a transaction that involves transferring money between two bank accounts. If the transfer fails mid-process, the transaction must be rolled back to ensure the money is not lost.


2. What is the main reason to use typing in software development (e.g. in TypeScript)?

Answer:

Easy detection of errors and bugs.

Explanation:

Static typing, as in the case of TypeScript, helps identify type errors during development, before the code is even executed. This can significantly reduce the number of bugs related to incorrect data types, making maintenance easier and improving code quality.

Example:

In TypeScript, when declaring a variable as let age: number = "25";, the compiler will generate an error, because we are assigning a string to a variable of type number.


3. What is the benefit of using an ORM (Object-Relational Mapper) in an application?

Answer:

To simplify the process of mapping objects to database tables.

Explanation:

ORMs allow you to work with objects in code and automatically map them to database tables without having to write SQL directly. This facilitates interaction with the database, increasing productivity and avoiding common SQL errors.

Example:

With an ORM like Sequelize (for Node.js), when you create a User object, you can automatically save and retrieve that object to the database without writing SQL queries manually.


4. What is the main difference between null and undefined in JavaScript?

Answer:

"Null" is explicitly assigned to indicate the absence of any object value, while "undefined" is the default value for uninitialized variables.

Explanation:

  • null is a value explicitly assigned to indicate the absence of a value or object.
  • undefined is the default value for variables that are declared but not initialized.

Example:

let a = null;  // null é atribuído explicitamente
let b;         // b é undefined porque não foi inicializado

console.log(a);  // null
console.log(b);  // undefined
Copy after login
Copy after login

5. How can Flexbox be used to horizontally center an element within its parent container?

Answer:

Apply the "display: flex" property to the parent container and use the "justify-content: center" property.

Explanation:

Flexbox makes it easy to align elements. To center an element horizontally, you must configure the parent container with display: flex and use justify-content: center to align the items horizontally in the center.

Example:

.container {
  display: flex;
  justify-content: center;
}

.item {
  width: 50%;
}
Copy after login
<div>




<hr>

<h3>
  
  
  6. <strong>Como otimizar o pseudocódigo para verificar se um número N é primo?</strong>
</h3>

<p><strong>Resposta:</strong><br><br>
<strong>Utilizar a raiz quadrada de N como limite superior do loop.</strong></p>

<p><strong>Explicação:</strong><br><br>
Em vez de verificar todos os números até (N-1), você pode verificar até a raiz quadrada de (N). Isso reduz significativamente a quantidade de verificações, pois, se (N) tem um divisor maior que sua raiz quadrada, o outro divisor já terá sido encontrado antes.</p>

<p><strong>Exemplo:</strong><br>
</p>

<pre class="brush:php;toolbar:false">function isPrime(N) {
  if (N <= 1) return false;
  for (let i = 2; i <= Math.sqrt(N); i++) {
    if (N % i === 0) return false;
  }
  return true;
}
console.log(isPrime(29));  // true
Copy after login

7. What is the purpose of transactions in SQL?

Answer:

Ensure the integrity of data stored in the database.

Explanation:

Transactions in SQL are used to ensure that operations on the database are completed correctly or otherwise rolled back. This ensures that the database remains consistent even in the event of a failure.

Example:

In a sales transaction, if payment fails after inventory is updated, the transaction can be rolled back to ensure that inventory is not updated without payment being made.


8. Which command in Git undoes a merge performed incorrectly?

Answer:

git merge --abort

Explanation:

If you run a merge and realize that you brought in changes from the wrong branch, you can use the git merge --abort command to cancel the merge and return to the previous state, without the changes being applied.

Example:

git merge feature-branch
# Se perceber que o merge foi feito na branch errada
git merge --abort
Copy after login

9. What is the main benefit of using an ORM (Object-Relational Mapper)?

Answer:

To simplify the process of mapping objects to database tables.

Explanation:

ORM allows you to work with objects in your code, and ORM takes care of mapping these objects to the database automatically, without having to write SQL directly.

Example:

Using the Sequelize ORM, when you create a new user, it automatically saves the data to the database without you writing SQL:

let a = null;  // null é atribuído explicitamente
let b;         // b é undefined porque não foi inicializado

console.log(a);  // null
console.log(b);  // undefined
Copy after login
Copy after login

These examples and explanations should help you better understand the concepts covered in the programming questions.

The above is the detailed content of DEV Interview Questions. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template