2_Data Types
2_Data Types
Data Types
Primitive Data Types
• Character (blood=“A”)
• Number (num1=100, price=35.5)
• Boolean
• String (name= “aye aye”)
1
Type coercion
"ABC" > 123
No Error. Convert ABC to number. The value is zero. Zero is not greater than 123. So , the result
is false.
String
Single Quote, Double Quote and Back tick
let blood = "A" (using double quote)
let greet = 'Hello' (using single quote)
let time = '3 O\' Clock' (no error with using Backslash)
2
Special Data Types
• Undefined
• null
• NaN
Undefined Variable
let myvar
null Variable
3
Exercises
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Numbers</h2>
<p>Numbers can be written with, or without decimals:</p>
<p id="demo"></p>
<script>
let x1 = 34.00;
let x2 = 34;
let x3 = 3.14;
document.write(x1 + "<br>" + x2 + "<br>" + x3)
</script>
</body>
</html>
<html>
<body>
<h2>JavaScript Strings</h2>
<p>You can use quotes inside a string, as long as they don't match the quotes
surrounding the string:</p>
<p id="demo"></p>
<script>
let answer1 = "It's alright";
let answer2 = "He is called 'Johnny'";
let answer3 = 'He is called "Johnny"';
document.write( answer1 + "<br>" + answer2 + "<br>" + answer3)
</script>
</body>
</html>