Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

Javascript Notes #2

Uploaded by

mauismallbiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Javascript Notes #2

Uploaded by

mauismallbiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Data Types

A data type refers to the type of data that a javascript variable can hold. there
are seven primitive data types in JS

- In JS a primitive (primitive value / primitive data type) is data that is not an


object and has no native methods or properties
- (However, JS enables access to methods and properties acssociated with prim
types such as string / number / boolean)
- This functionality is due to JS ability to implicitly convert primitives to
object with wrapper objects when necessary
- A significant difference between primitive data types and non-primitives is that
primitive types can only contain one value and that value must be of the same
primitive type
- In contrast non-primitives can accomodate various different numbers of values and
these values can all be of different primitive types
- This flexibility is evident in data structures like arrays and objects.’
- When properties are accesed on primitives, JS auto-boxes the value into a wrapper
object and accesses the property on that object instead.

There are 7 primitive data types:

- string
- In any computer programming language, a string is a sequence of [characters]
(https://developer.mozilla.org/en-US/docs/Glossary/Character) used to represent
text.
- number
- In [JavaScript](https://developer.mozilla.org/en-US/docs/Glossary/
JavaScript), **Number** is a numeric data type in the [double-precision 64-bit
floating point format (IEEE
754)](https://en.wikipedia.org/wiki/Double_precision_floating-point_format)
- bigint
- In [JavaScript](https://developer.mozilla.org/en-US/docs/Glossary/
JavaScript), **BigInt** is a numeric data type that can represent integers in
the [arbitrary precision format](https://en.wikipedia.org/wiki/Arbitrary-
precision_arithmetic)
- boolean
- a **Boolean** is a logical data type that can have only the values true or
false.
- undefined
-
a [primitive](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) value
automatically assigned
to [variables](https://developer.mozilla.org/en-US/docs/Glossary/Variable) that
have just been declared, or to formal [arguments](https://developer.mozilla.org/en-
US/docs/Glossary/Argument) for which there are no actual arguments.
- symbol
- a built-in object whose constructor returns a
Symbol [primitive](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) —
also called a **Symbol value** or just a **Symbol** — that's guaranteed to be
unique. Symbols are often used to add unique property keys to an object that won't
collide with keys any other code might add to the object
- null
- represents a reference that points, generally intentionally, to a nonexistent
or invalid [object](https://developer.mozilla.org/en-US/docs/Glossary/Object) or
address.
- In [JavaScript](https://developer.mozilla.org/en-US/docs/Glossary/
JavaScript), null is marked as one of the [primitive
values](https://developer.mozilla.org/en-US/docs/Glossary/Primitive), because its
behavior is seemingly primitive. However, when using the typeof operator, it
returns “object”.

Object

- JS object is a data structure that allows us to have key >> value pairs
- So we can have distinct keys and each key is mapped to a value that can be of any
JS data type
- Built-in objects or “global objects”, are those built into the language
specification itself.
- There are numerous built-in objects within the JS language all of wich are
accessable at the global scope.
- Number
- Math
- Date
- String
- Error
- Function
- Boolean
- [More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
Global_Objects)

- TypeOf Operator
- You can use the typeOf opertator to find the data type of a JS variable it
returns a string indicating the type of provided
[operand’s](https://developer.mozilla.org/en-US/docs/Glossary/Operand) value

Prototypes

- JS is an object-oriented language built around a prototype model


- Every object in JavaScript has a built-in property, which is called
its **prototype**. The prototype is itself an object, so the prototype will have
its own prototype, making what's called a **prototype chain**.
- In JS, every object inherits properties from its prototype, if there are any

You might also like