Below are different data types in javascript:
1. Number
Any number from integer to floating (with decimals) as long as it doesn't exceed the limit for integers just like in java. It has special numeric values, infinity, -infinity and NaN. Infinity and - inifinity is just the same in Math. NaN is for errors and performing mathematical operations in errors result into an error except when the operation is NaN**0 = 1. In this type, you can use the common mathematical operation like addition(+), subtraction(-), multiplication(*) and division(/).
==============
let x= 5;
==============
2. BigInt
It is the same with number but the values ends in a suffix n and also the value's limit is way too larger than Number.
==============
let x = 5n;
==============
3. String
It is compose of characters that is inside either doubles quotes or single quotes.
==============
let name = "slam dunk";
name = 'sketchy';
==============
But if you want to embed a variable or a function, you used back ticks('). And inside it, you add a dollar sign followed by braces ${} so you can add the variable or function you want to be added.
==============
let name = "sketchy";
let display = 'My name is ${name}';
==============
4. Boolean
It contains true or false values only.
5. null
It means nothing or empty.
6. undefined
It means that you haven't assigned any value to your variable.
7. Symbols
This type creates a unique identifier to objects but this and the other six types belong to primitive types.
8. object
It is a non primitive. It stores a collection of data about something. It is just like a class in java which contains properties and functions but can be assigned directly to a variable which will serve as its name. It is like a block in java where inside it contains a key and value pair separated by a colon and its key-value pair is separated by a comma.
==============
let x = {
name: "sketchy",
age: 100
};
=============
typeof - it is an operator that is equivalent to instanceof in java. It simply gives the type of whatever is you are evaluating.
===============
let x = 5;
function checkType(){
return typeof x;
}
===============
HTML
document.write(checkType())
Result:
number
YOU ARE READING
Javascript Programming
RandomI am just documenting things what i learned online in here. I do express things in my own words. And I create my own program samples which serves as my practice. I do this so that when someday I would need some notes to review, I can just visit in h...
