Here is a list of programming questions, with explanatory answers and additional examples for each:
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.
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.
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.
Answer:
"Null" is explicitly assigned to indicate the absence of any object value, while "undefined" is the default value for uninitialized variables.
Explanation:
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
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%; }
<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
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.
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
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
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!