In JavaScript , almost everything is object exception primitive types.
- Objects can be Booleans (if defined with the new keyword)
- Objects can be numbers (if defined with the new keyword)
- Objects can be strings (if defined with the new keyword)
- All dates are objects.
- Math is always about objects.
- Invariably, regular expressions are objects.
- All arrays are objects.
- All functions are objects.
Object can be single value, name:value pair and methods .
Example Code;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <p id="div1"></p> <br /> <p id="div2"></p> <script type="text/javascript"> const person = { //person object name: Shri, //object property age: 30, //object property job: () => { // object function return "Developer" } }; document.getElementById("div1").innerHTML = person.name; // Output: Shri document.getElementById("div2").innerHTML = person.job(); // Output: 30 </script> </body> </html> |
Output:
Shri
Developer