Javascript: Data Types and Structures

Checking the Type

const typeChecking = "This is a string"console.log(typeof typeChecking) // output: string

Number

const number = 99const bigNumber = 1.8 * Math.pow(10, 307)const infinity = number * bigNumberconsole.log(number) // output: 99console.log(bigNumber) // output: 1.8e+307console.log(infinity) // output: Infinity

String

const string = "Storing a srting."
const anotherString = 'Storing another string'

BigInt

const bigint = 999999nconst anotherBigint = BigInt(999999)console.log(typeof bigint) // output: bigintconsole.log(typeof anotherBigint) // // output: bigint

Symbol

const sym = Symbol(1)const anotherSym = Symbol(1)console.log(sym === anotherSym) // output: false// Used as object keysconst user = [{
user1: "name1",
id: sym
},
{
user2: "name2",
id: anotherSym
}]

Boolean

const a = 1const b = 2const c = 1console.log(a === b) // output: flaseconsole.log(a === c) // output: true

Undefined

let withoutValues;function returnsNothing () { const a = 1; const b = 2 a + b;};console.log(typeof withoutValues); // output: undefinedconsole.log(returnsNothing()); // output: undefined

Null

let withoutValues;let withNull = null;console.log(typeof withoutValues); // output: undefinedconsole.log(typeof withNull); // output: object

Object

const user = { username: "name", id: 345, friends: ["user1", "user2"], email: "user@example.com"}console.log(typeof obj) // output: object

Function

function addNums (a, b) { const c = 3 return a + b + c}console.log(addNums(1, 2)) // oupput: 6

So Where Does The Array Fits Into All These?

const underneathAnArray = {
"0" : 1,
"1" : 2,
"2" : 4,
"3" : 7,
"4" : 8,
"5" : 0,
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store