Data Types - Primitives
Use Javascript to explore primitive data types in the console.
by ow3n
HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
<div class="container">
<h3>Data Types - Primitives</h3>
Open the Javascript Console and click each below to see the data
<div class="my-2">
<button class="btn btn-light" id="boolean">Boolean</button>
<button class="btn btn-light" id="integer">integer</button>
<button class="btn btn-light" id="float">float</button>
<button class="btn btn-light" id="string">string</button>
<button class="btn btn-light" id="trivial">trivial</button>
</div>
</div>
JavaScript
window.onload = function() {
// boolean
document.getElementById('boolean').onclick = function() {
console.log("### boolean ###");
console.log(true, typeof true);
console.log(false, typeof false);
}
// integer
document.getElementById('integer').onclick = function() {
console.log("### boolean ### (In Javascript there is only one number type)");
console.log(-4, typeof - 4);
console.log(1, typeof 1);
console.log(45, typeof 45);
console.log(10000000000, typeof 10000000000);
}
// float
document.getElementById('float').onclick = function() {
console.log("### float ### (In Javascript, floats are also numbers)");
console.log(3.14, typeof 3.14);
console.log(0.0000001, typeof 0.0000001);
console.log(10000000000.0, typeof 10000000000.0);
}
// string
document.getElementById('string').onclick = function() {
console.log("### string ###");
console.log("hello world 😀", typeof "hello world 😀");
console.log('2 be or not 2 be', typeof '2 be or not 2 be');
console.log(`favorite numbers: 1, 2, and 3.14`, typeof `favorite numbers: 1, 2, and 3.14`);
}
// trivial
document.getElementById('trivial').onclick = function() {
console.log("### trivial ###");
var nullVar = null;
console.log(nullVar, typeof nullVar);
var undefinedVar;
console.log(undefinedVar, typeof undefinedVar);
}
}