DEV Community

Manisha Kundrapu
Manisha Kundrapu

Posted on

Revision 10-03-2023

1. In JavaScript how do you check whether an object is an array or not?

In JavaScript, you can check whether an object is an array or not using the Array.isArray() method.

2. Is the data list tag and select tag the same?

While the and HTML tags are both used to present a list of options to the user, they are not the same.

The tag is used to create a dropdown list of options that the user can select from. When the user clicks on the dropdown, a list of options is displayed and the user can choose one of the options. The selected option is then displayed in the dropdown.

The tag, on the other hand, is used to create a list of options that are displayed as suggestions while the user is typing in an input field. When the user types a character in the input field, a list of suggested options is displayed below the input field. The user can then select one of the suggested options, or continue typing to refine the suggestions.

3. When merge conflict occurs in git?

A merge conflict in Git occurs when two or more developers make changes to the same part of a file, and those changes conflict with each other.

4. Why do we use the typeof operator in JavaScript?

The typeof operator is used to determine the data type of a given value or expression.

It returns a string indicating the type of the operand.

5. What is the difference between "===" and "==" in JavaScript?

The == operator checks whether the values of two operands are equal or not, regardless of their data types. If the values are equal, it returns True. If they are not equal, it returns False.

The === operator also compares two values for equality, but it does take their data type into account. This means that if the two values have different data types, the comparison will return false.

6. What is the difference between CSS border and outline?

CSS border properties allow us to set the style, color, and width of the border.

CSS outline property allows us to draw a line around the element, outside the border.

7. When do we use let and const instead of var in JavaScript?

var declarations are globally scoped or function scoped while let and const are block scoped.

var variables can be updated and re-declared within its scope.

let variables can be updated but not re-declared, const variables can neither be updated nor re-declared.

They are all hoisted to the top of their scope.

8. What is the difference between shared lock and exclusive lock in a transaction?

A shared lock allows multiple transactions to read the same data concurrently, but only one transaction can modify the data at a time.

An exclusive lock allows a single transaction to modify the data while blocking all other transactions from reading or modifying it.

9. What is hoisting in JavaScript?

Hoisting is a mechanism where variable and function declarations are moved to the top of their respective scopes, before the code is executed. This means that variables and functions can be used in code before they are declared, without causing a syntax error.

10. How is user authentication data fetched from forms in web pages?

User authentication data can be done using JWT where it will be added as a middleware in the backend to check the credentials that is stored in the backend in the form of token.

In a JWT-based authentication system, user authentication is done using the following steps:

  • The user enters their credentials into a form on a web page and submits the form.

  • The server verifies the user's credentials and, if they are valid, generates a JSON Web Token (JWT) containing a payload with the user's information (such as their user ID, role, and any other relevant data) and signs it using a secret key.

  • The JWT is then returned to the client and is included in all subsequent requests made by the client.

  • The backend typically has a middleware (or multiple middlewares) that are responsible for handling user authentication.

  • When a request is received by the backend, the JWT is extracted from the request and verified using the same secret key that was used to sign it.

  • If the JWT is valid, the user is considered authenticated and the request is processed.

  • If the JWT is invalid (e.g., because it has been tampered with or has expired), the user is considered unauthenticated and the request is rejected.

11. What is the git command to update username and email locally?

git config user.name "NewUserName"
git config user.email "new.email@example.com"
Enter fullscreen mode Exit fullscreen mode

12. What is an expression and statement in JavaScript?

An expression is any piece of code that can be evaluated to produce a value.

For example, 5 + 3 is an expression that evaluates to the value 8.

Other examples of expressions include variable references, function calls, and logical operators.

A statement, on the other hand, is a complete unit of code that performs some action.

It typically ends with a semicolon ;.

Examples of statements in JavaScript include variable declarations, function declarations, loops, conditional statements, and assignments.

Here are some examples to illustrate the difference between expressions and statements:


// Expression example
let sum = 5 + 3; // The expression "5 + 3" evaluates to the value 8

// Statement example
if (sum === 8) {
  console.log("The sum is 8!"); // The entire "if" block is a statement that logs a message to the console
}
Enter fullscreen mode Exit fullscreen mode

In this example, 5 + 3 is an expression that is assigned to the variable sum, which is a statement. The if block is a statement that includes an expression (sum === 8) as its condition, and another statement (console.log()) as its body.

Top comments (0)