Javascript 9

Javascript 9

Chapter 9 with Examples

Hi everyone, My name is Arinze Calistus. The purpose of this blog is to teach you all you need to know about JavaScript.

Javascript is Dynamic

It may interest you to know that JS is a dynamic language. Variables are not directly associated with a single data type, unlike in other programming languages. Any variable in JS can be reassigned to values of all types.

For Example

var x = " text "; // x is a string
x = true; // x is now a boolean
x = 24;  // x is now a number
document.write(x);

The typeOf Operator

The typeof returns a string indicating the data type of the evaluated operand.

typeOf "Her name is Rachell."; // returns "string"
typeOf 34; // returns "number"
typeOf true; // returns "boolean"
typeOf undefined; // returns "undefined"

Primitive Data

Primitive data are data that are not object and has no methods. There are 4 basic primitive data types:

  • string

  • number

  • boolean

  • undefined

All these primitive data types can be returned by the typeOf operator. Just like in the previous example.

Thanks for reading!!