Skip to main content

Command Palette

Search for a command to run...

Datatypes in Javascript

Published
1 min readView as Markdown
N

Aspiring Full stack developer

We all know that Data is piece of information that we often work with in any programming language. So each data has its own type. for ex:

// below are the mostly repeated type of data in JS.
console.log('Nithin')
console.log(23)
console.log(true)
console.log(undefined)
console.log(null)

console.log([1,2,3])
console.log({name: 'ntihin', age:23})

So values in JS are can either be primitive or non primitive (Objects)

Primitive Data types

Primitive data types are string, number, boolean, undefined, null

string: sequence of characters. always must be within single or double quotes.
number: Floating point numbers. even if u assign 23, compilers will automatically convert them to 23.0
boolean: either true or false. always been used during decision making time.
undefined: This datatype is being assigned implicitly when you declare a variable without assigning any value to it.
null: its. a explicit value that you used initialize when u dont know the value initially?

console.log('Nithin') // string
console.log(23)  // number
console.log(true) // boolean
console.log(undefined) // undefined
console.log(null) // null

Non-primitive datatypes
Non-primitive data types are arrays, functions, objects literals, Date objects etc…

const arr = [1, 2, 3, 4] // arrays

// functions
function greet() {
console.log('greeting')
}

greet()

console.log(new Date())

const user = {
fName: 'Nithin',
age: 23
}

console.log(user)