Tech Study

JavaScript Type Conversion

JavaScript has a type conversion mechanism that can explicitly or implicitly convert a value of one data type to a value of another data type. Type conversion is a method of converting one data type to another. Type conversion is often used when building applications with Javascript.

JavaScript has two types of type conversions.

  • Implicit conversions:

Implicit conversions are type conversions that happen automatically when converting to or returning from a functionType call. Implicit type conversion occurs automatically when an operation is performed between values ​​of different data types, such as adding a number to a string.

Example:

let a = "5";

Let b = 10;

let c = a + b;

console. log(c);

Output:

 510

 

In the example above, the string value a is implicitly converted to a number when added to b.

  • Explicit Conversion:

An Explicit type conversion is when you explicitly request that a value be converted to a specific type. A type conversion performed manually by some function or method. The following methods are available for explicit type conversion in JavaScript.

  1. String(): Convert value to string.
  2. Number(): Converts a value to a number.
  3. Boolean(): Convert value to boolean.
  4. parseInt(): Convert string to integer.
  5. parseFloat(): Converts a string to a hexadecimal number.

Example:

let a = "5";

Let b = 10;

let c = Number(a) + b;

console.log(c);

Output: 

15

 

In the example above, the string value a is explicitly converted to a number using the Number() function, and the result of the addition operation is the expected number 15.

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more