0% found this document useful (0 votes)
12K views

Data Types

1. There are 8 basic data types in JavaScript: number, bigint, string, boolean, null, undefined, object, and symbol. 2. Numbers represent both integers and floating point numbers and have special values like Infinity, -Infinity, and NaN. BigInt was added for integers of arbitrary size. 3. Strings can be defined using double quotes, single quotes, or backticks and allow embedding of expressions using ${ }.

Uploaded by

joshuaharris1107
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12K views

Data Types

1. There are 8 basic data types in JavaScript: number, bigint, string, boolean, null, undefined, object, and symbol. 2. Numbers represent both integers and floating point numbers and have special values like Infinity, -Infinity, and NaN. BigInt was added for integers of arbitrary size. 3. Strings can be defined using double quotes, single quotes, or backticks and allow embedding of expressions using ${ }.

Uploaded by

joshuaharris1107
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

DATA TYPES:

A value in JavaScript is always of a certain type. For example, a string or a


number (In Java ro C# it is called an int/integer).

There are eight basic data types in JavaScript, which include:


1. Number
2. BigInt
3. String
4. Boolean
5. The "null" value
6. The "undefined" value
7. Objects
8. Symbols

The number type represents both integer and floating point numbers.
There are many operations for numbers, e.g. multiplication, division, addition,
subtraction, and so on.

Besides regular numbers, there are so-called special numeric values which also
belong to this data type:
1. Infinity
2. -Infinity
3. NaN (Not a Number)

Infinity represents the mathematical Infinity. It is a special value thats greater


than any number.
NaN represents a computational error. It is a result of an incorrect or an
undefined mathematical operation.
NaN is sticky. Any further mathematical operation on NaN returns NaN, so if there
is a NaN somewhere in a mathematical expression, it propagates to the whole result.
There is only one exception to that: NaN ** 0 is 1.

BIGINT:

In JavaScript, the "number" type cannot safely represent integer values larger than
2^53 -1 (thats 9007199254740991), or less than -(2^53 -1) for negatives.To be
really precise, the "number" type can store larger integers (up to
1.7976931348623157 * 10^308), but outside of the safe integer range, there will be
a precision error, because not all digits fit into the fixed 64-bit storage. So an
"approximate" value may be stored.

The BigInt type was recently added to the language to represent integers of
arbitrary length.
A BigInt value is created by appending "n" to the end of an integer.

STRING:

In JavaScript, a string can be surrounded by quotes.

There are three types of quotes:

1. Double quotes ("")


2. Single quotes ('')
3. Backticks: (``)
Double and single quotes are "simple" quotes. There's practically no difference
between them in JavaScript. Backticks are "extended functionality" quotes. They
allow us to embed variables and expressions into a string by wrapping them in "$
{ }", for example:

const name = "John";

alert(`Hello, ${name} `);

I recommend using the backticks regardless for the following reasons:

1. If you use double quotes, the only other quotes you can use are single
quotes, which will mainly be used for contractions.
2. If you use single quotes, it will throw an error if you try and use
contractions such as wasn't because a contraction uses a single quote.
3. If you use the backticks, you have two other types of quotes available as
well as the fuctionality to use the ${ } straight away.

In JavaScript, there is not character type. There is only one type which is known
as string. A string may be empty, or have one or more characters.

BOOLEAN:

The boolean type has only two values: true and false.

This type is commonly used to store yes/no values: true means "yes/correct" and
false means "no/incorrect".

THE "NULL" VALUE:

The special null value does not belong to any of th etypes described above. It
forms a separate type of its own which contains only the null value.

In JavaScript, null is not a "reference to a non-existing object" or a "null


pointer" like in some other languages.
It is a special value which represents "nothing", "empty", or "value unknown".

THE "UNDEFINED" VALUE:

The special value "undefined" also stands apart. It makes a type of its own, just
like null.
The meaning of undefined is "value is not assigned".
If a variable is declared, but not assigned, then its value is undefined.
Technically it is possible to explicitly assign undefined to a variable, but it is
not recommended. Normally, one uses null to assign an "empty" or "unknown" value to
a variable, while undefined is reserved as a default initial value for unassigned
things.

OBJECTS AND SYMBOLS:

The object type is special.

All other types are called "primitive" because their values can contain only a
single thing (be it a string or a number or whatever). In contrast, objects are
used to store collections of data and more complex entities.

The symbol type is used to create unique identifers for objects. We have to mention
it here for the sake of completeness, but also postpone the details till we know
objects.

THE TYPEOF OPERATOR:

The typeof operator returns the type of an operand. It is useful when we want to
process values of different types differently or just want to do a quic

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy