We don't have class in our ICT Class on Monday and Tuesday. On wednesday, I've finished my exercise 2 and 3. While on friday, I had finished my exercise 4. But I did'nt know how to make the exercise 5. I tried my best.
Here are examples.
Number() converts to a Number, String() converts to a String, Boolean() converts to a Boolean.
JavaScript Data Types
In JavaScript there are 5 different data types that can contain values:
- string
- number
- boolean
- object
- function
There are 3 types of objects:
- Object
- Date
- Array
And 2 data types that cannot contain values:
- null
- undefined
The typeof Operator
You can use the typeof operator to find the data type of a JavaScript variable.
Example
typeof "John" // Returns string typeof 3.14 // Returns numbertypeof NaN // Returns numbertypeof false // Returns booleantypeof [1,2,3,4] // Returns objecttypeof {name:'John', age:34} // Returns objecttypeof new Date() // Returns objecttypeof function () {} // Returns functiontypeof myCar // Returns undefined (if myCar is not declared)typeof null // Returns object
Please observe:
- The data type of NaN is number
- The data type of an array is object
- The data type of a date is object
- The data type of null is object
- The data type of an undefined variable is undefined
You cannot use typeof to define if an object is an JavaScript Array or a JavaScript Date.
Taken from http://www.w3schools.com/js/js_type_conversion.asp.
Taken from http://www.w3schools.com/js/js_type_conversion.asp.
0 comments:
Post a Comment