JavaScript data types & conversion data types

Data types & conversion types

Data types that are primitives:

Boolean: true and false.

null: A special keyword denoting a null value.

(Because JavaScript is case-sensitive, null is not the same as Nul, NULL, or any other variant.)

undefined: A top-level property whose value is not defined.

Number: An integer or floating-point number. 

For example 42 or 3.14159.

DATA TYPES

Data types that are primitives:

BigInt: An integer with arbitrary precision.

For example: 90071992547 40992n.

String: A sequence of characters that represent a text value. For example: “Howdy”

Symbol: A data type whose instances are

unique and immutable.

DATA TYPES

…and Object.

DATA CONVERSION

JavaScript is a dynamically typed language.

This means you don’t have to specify the data type of a variable when you declare it.

It also means that data types are automatically converted as-needed during script execution.

DATA CONVERSION

For example, a variable is defined as Number:

* * *

var answer =42;

Later, the same variable can be assigned a string value, for example:

* * *

answer = ‘Thanks for all the love … ‘;

DATA CONVERSION

Expressions involving numeric and string values with the +operator, JavaScript converts numeric values to strings.

* * *

X = ‘The answer is   ‘ + 42 / / “The answer is 42”

y = 42 +  ‘ is the answer’ / / “42 is the answer”

With all other operators, JavaScript does not convert numeric values to strings.

* * *

X =’37’ -7; / / 30

y = ’37’ + 7; //  “377”

Leave a Reply

Your email address will not be published. Required fields are marked *