SlideShare a Scribd company logo
Couple-O-Points
● JavaScript is a “loosely typed” or “dynamic”
language.
● So we don’t have to declare type of a variable
ahead of time.
● You can check the type of any variable using
‘typeof’ operator
Data Types in JavaScript
● Numbers
● Strings
● Boolean
● Objects
● Undefined
● Null
Numbers
● JavaScript has single number type
● It is represented as 64-bit floating point
● No separate type of Integer (like Java etc.)
● 2e3 means 2000 i.e 2 multiplied by 10 raised to the power
after ‘e’ symbol.
● In addition, Number type also has three symbolic values
– Infinity
– -Infinity
– NaN
Strings
● Set of “elements” of 16-bit unsigned integer values.
● Each element in the String occupies a position in String
● Strings are immutable
● Strings have methods, useful ones, like:
– length()
– ToUpperCase()
● New strings can be made using concatenation (‘+’)
operator. Interesting case:
– ‘r’ + ‘a’ + ‘j’ === ‘raj’
Boolean
● Represents logical entity
● Can have two values
– true
– false
Objects
● Objects are collection of properties
● Properties can be removed and added, after
object has been created
● Object is a mapping between keys and values
– A key value is either a symbol or string value
– Values can be of any type i.e Number,
Boolean, Object etc
● Objects are mutable.
Undefined
● It’s a property of global object
● A variable that has not been assigned a value is
of type undefined.
● A function returns undefined if a value was not
returned.
Null
● Represents absence of any object value
● Operation “typeof null” yields “object”
Exercise
● What are the differences between “null” and
“undefined”?
● How would you test that a variable is defined
and has a non-null value?
Exercise
● What are the differences between “null” and
“undefined”?
● How would you test that a variable is defined
and has a non-null value?

More Related Content

Datatype in JavaScript

  • 1. Couple-O-Points ● JavaScript is a “loosely typed” or “dynamic” language. ● So we don’t have to declare type of a variable ahead of time. ● You can check the type of any variable using ‘typeof’ operator
  • 2. Data Types in JavaScript ● Numbers ● Strings ● Boolean ● Objects ● Undefined ● Null
  • 3. Numbers ● JavaScript has single number type ● It is represented as 64-bit floating point ● No separate type of Integer (like Java etc.) ● 2e3 means 2000 i.e 2 multiplied by 10 raised to the power after ‘e’ symbol. ● In addition, Number type also has three symbolic values – Infinity – -Infinity – NaN
  • 4. Strings ● Set of “elements” of 16-bit unsigned integer values. ● Each element in the String occupies a position in String ● Strings are immutable ● Strings have methods, useful ones, like: – length() – ToUpperCase() ● New strings can be made using concatenation (‘+’) operator. Interesting case: – ‘r’ + ‘a’ + ‘j’ === ‘raj’
  • 5. Boolean ● Represents logical entity ● Can have two values – true – false
  • 6. Objects ● Objects are collection of properties ● Properties can be removed and added, after object has been created ● Object is a mapping between keys and values – A key value is either a symbol or string value – Values can be of any type i.e Number, Boolean, Object etc ● Objects are mutable.
  • 7. Undefined ● It’s a property of global object ● A variable that has not been assigned a value is of type undefined. ● A function returns undefined if a value was not returned.
  • 8. Null ● Represents absence of any object value ● Operation “typeof null” yields “object”
  • 9. Exercise ● What are the differences between “null” and “undefined”? ● How would you test that a variable is defined and has a non-null value?
  • 10. Exercise ● What are the differences between “null” and “undefined”? ● How would you test that a variable is defined and has a non-null value?