{"id":18952835,"url":"https://github.com/sujon-ahmed/practice-javascript-object","last_synced_at":"2026-05-10T02:40:21.344Z","repository":{"id":109467726,"uuid":"516017090","full_name":"Sujon-Ahmed/practice-javascript-object","owner":"Sujon-Ahmed","description":"In this repository, I will practice JavaScript Object ","archived":false,"fork":false,"pushed_at":"2022-09-24T16:22:15.000Z","size":50,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-01T02:41:51.634Z","etag":null,"topics":["boostrap5","css3","html5","javascript"],"latest_commit_sha":null,"homepage":"https://sujon-ahmed.github.io/JavaScript-Object/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sujon-Ahmed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-20T14:34:10.000Z","updated_at":"2023-02-13T11:46:19.000Z","dependencies_parsed_at":"2023-05-17T23:15:35.387Z","dependency_job_id":null,"html_url":"https://github.com/Sujon-Ahmed/practice-javascript-object","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sujon-Ahmed%2Fpractice-javascript-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sujon-Ahmed%2Fpractice-javascript-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sujon-Ahmed%2Fpractice-javascript-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sujon-Ahmed%2Fpractice-javascript-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sujon-Ahmed","download_url":"https://codeload.github.com/Sujon-Ahmed/practice-javascript-object/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239952598,"owners_count":19723922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boostrap5","css3","html5","javascript"],"created_at":"2024-11-08T13:34:45.265Z","updated_at":"2026-03-29T13:30:20.636Z","avatar_url":"https://github.com/Sujon-Ahmed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## JavaScript-Object\n\n**In JavaScript, objects are king. If you understand objects, you understand JavaScript.**\n\nIn JavaScript, an object is a standalone entity, with properties and type. Compare it with a cup, for example. A cup is an object, with properties. A cup has a color, a design, weight, a material it is made of, etc. The same way, JavaScript objects can have properties, which define their characteristics.\n\nThe values are written as name:value pairs (name and value separated by a colon).\n\n\n*🔰 It is a common practice to declare objects with the const keyword.*\n\n``` javascript\nconst person = {firstName:\"John\", lastName:\"Doe\", age:50, eyeColor:\"blue\"};\n```\n\nIn JavaScript, almost \"everything\" is an object.\n\n- Booleans can be objects (if defined with the `new` keyword)\n- Numbers can be objects (if defined with the `new` keyword)\n- Strings can be objects (if defined with the `new` keyword)\n- Dates are always objects\n- Maths are always objects\n- Regular expressions are always objects\n- Arrays are always objects\n- Functions are always objects\n- Objects are always objects\n\nAll JavaScript values, except primitives, are objects.\n\n## JavaScript Primitives\nA primitive value is a value that has no properties or methods.\n\n`3.14` is a primitive value\n\nA primitive data type is data that has a primitive value.\n\nJavaScript defines 7 types of primitive data types:\n\n- **string**\n- **number**\n- **boolean**\n- **null**\n- **undefined**\n- **symbol**\n- **bigint**\n\n|   Value           |   Type            |   Comment                         |\n|-------------------|-------------------|-----------------------------------|\n|   \"Hello\"         |   string          |   \"Hello\" is always \"Hello\"       |\n|   3.14            |   number          |   3.14 is always 3.14             |\n|   true            |   boolean         |   true is always true             |\n|   false           |   boolean         |   false is always false           |\n|   null            |   null (object)   |   null is always null             |\n|   undefined       |   undefined       |   undefined is always undefined   |\n\n\n## What is this?\nIn JavaScript, the `this` keyword refers to an object.\n\nWhich object depends on how `this` is being invoked (used or called).\n\nThe `this` keyword refers to different objects depending on how it is used:\n\n- In an object method, `this` refers to the object.\n- Alone, `this` refers to the global object.\n- In a function, `this` refers to the global object.\n- In a function, in strict mode, `this` is `undefined`.\n- In an event, `this` refers to the element that received the event.\n- Methods like `call()`, `apply()`, and `bind()` can refer `this` to any object.\n\n\u003e `this` is not a variable. It is a keyword. You cannot change the value of `this`.\n\n## JavaScript Accessors (Getters and Setters)\nECMAScript 5 (ES5 2009) introduced Getter and Setters.\n\nGetters and setters allow you to define Object Accessors (Computed Properties).\n\n\n### Getter Example\n``` js\n// Create an object:\nconst person = {\n  firstName: \"John\",\n  lastName: \"Doe\",\n  language: \"en\",\n  get lang() {\n    return this.language;\n  }\n};\n\n// Display data from the object using a getter:\ndocument.getElementById(\"demo\").innerHTML = person.lang;\n```\n\n### Setter Example\n```js\nconst person = {\n  firstName: \"John\",\n  lastName: \"Doe\",\n  language: \"\",\n  set lang(lang) {\n    this.language = lang;\n  }\n};\n\n// Set an object property using a setter:\nperson.lang = \"en\";\n\n// Display data from the object:\ndocument.getElementById(\"demo\").innerHTML = person.language;\n```\n\n## JavaScript Function or Getter?\nWhat is the differences between these two examples?\n### Example-1\n```js\nconst person = {\n  firstName: \"John\",\n  lastName: \"Doe\",\n  fullName: function() {\n    return this.firstName + \" \" + this.lastName;\n  }\n};\n\n// Display data from the object using a method:\ndocument.getElementById(\"demo\").innerHTML = person.fullName();\n```\n### Example-2\n```js\nconst person = {\n  firstName: \"John\",\n  lastName: \"Doe\",\n  get fullName() {\n    return this.firstName + \" \" + this.lastName;\n  }\n};\n\n// Display data from the object using a getter:\ndocument.getElementById(\"demo\").innerHTML = person.fullName;\n```\n\u003e Example 1 access fullName as a function: person.fullName().\n\n\u003e Example 2 access fullName as a property: person.fullName.\n\n\u003e The second example provides a simpler syntax.\n\n### Why Using Getters and Setters?\n- It gives simpler syntax\n- It allows equal syntax for properties and methods\n- It can secure better data quality\n- It is useful for doing things behind-the-scenes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsujon-ahmed%2Fpractice-javascript-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsujon-ahmed%2Fpractice-javascript-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsujon-ahmed%2Fpractice-javascript-object/lists"}