{"id":217128,"date":"2019-12-26T10:26:03","date_gmt":"2019-12-26T10:26:03","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=217128"},"modified":"2019-12-30T09:20:32","modified_gmt":"2019-12-30T09:20:32","slug":"getter-setter-in-javascript","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/","title":{"rendered":"Getter Setter in Javascript"},"content":{"rendered":"\n<p>Getter and Setter are introduced in the ECMAScript 5. In JavaScript, Getter and Setter are the most powerful property to set the values of the object and you want to get the value which depends on the other values in the object. We need to use get and set keyword at the start of the method when we are declaring the getter and setter method. Getter and setter is the <strong>accessor property rather than the method<\/strong>. For example, you have a customer object with the first name and last name in the object and you want to get the value of the customer, then get the method will provide you the complete name of the customer.<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"678\" height=\"282\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png\" alt=\"P10\" class=\"wp-image-217132\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png 678w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10-300x125.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10-250x104.png 250w\" sizes=\"(max-width: 678px) 100vw, 678px\" loading=\"lazy\" \/><\/figure><\/div>\n\n\n\n<p><br> In this we did not need to call the getter method as a function, We just need to use it as a variable of the object only.<\/p>\n\n\n\n<p>In this, If you have created a getter method only then we can get the value of the object only, We can not set the values by declaring the setter method in the object.<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"734\" height=\"279\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P11.png\" alt=\"P11\" class=\"wp-image-217134\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P11.png 734w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P11-300x114.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P11-250x95.png 250w\" sizes=\"(max-width: 734px) 100vw, 734px\" loading=\"lazy\" \/><\/figure><\/div>\n\n\n\n<p>To make it work, We need to define the setter method as well.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"849\" height=\"503\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P12.png\" alt=\"P12\" class=\"wp-image-217137\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P12.png 849w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P12-300x178.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P12-250x148.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P12-768x455.png 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" loading=\"lazy\" \/><\/figure><\/div>\n\n\n\n<p>As we can check that fullname is virtual property of the object, With the help of the getter and setter, it is readable and writeable now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getter and Setter are introduced in the ECMAScript 5. In JavaScript, Getter and Setter are the most powerful property to set the values of the object and you want to get the value which depends on the other values in the object. We need to use get and set keyword at the start of the <a href=\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":226,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-217128","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Getter Setter in Javascript - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getter Setter in Javascript - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Getter and Setter are introduced in the ECMAScript 5. In JavaScript, Getter and Setter are the most powerful property to set the values of the object and you want to get the value which depends on the other values in the object. We need to use get and set keyword at the start of the [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-26T10:26:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-30T09:20:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png\" \/>\n<meta name=\"author\" content=\"Arun Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arun Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\"},\"author\":{\"name\":\"Arun Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/880586fc1e4703d9e951d86655682ffd\"},\"headline\":\"Getter Setter in Javascript\",\"datePublished\":\"2019-12-26T10:26:03+00:00\",\"dateModified\":\"2019-12-30T09:20:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\"},\"wordCount\":219,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\",\"url\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\",\"name\":\"Getter Setter in Javascript - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png\",\"datePublished\":\"2019-12-26T10:26:03+00:00\",\"dateModified\":\"2019-12-30T09:20:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png\",\"width\":678,\"height\":282,\"caption\":\"P10\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getter Setter in Javascript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/880586fc1e4703d9e951d86655682ffd\",\"name\":\"Arun Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/22744c127478ae0d9d9efb702c1379e4ae8c5538423ba70bb9a37dfeb92861c9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/22744c127478ae0d9d9efb702c1379e4ae8c5538423ba70bb9a37dfeb92861c9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Arun Kumar\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/arun-kumar350\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getter Setter in Javascript - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Getter Setter in Javascript - Webkul Blog","og_description":"Getter and Setter are introduced in the ECMAScript 5. In JavaScript, Getter and Setter are the most powerful property to set the values of the object and you want to get the value which depends on the other values in the object. We need to use get and set keyword at the start of the [...]","og_url":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2019-12-26T10:26:03+00:00","article_modified_time":"2019-12-30T09:20:32+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png","type":"","width":"","height":""}],"author":"Arun Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Arun Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/"},"author":{"name":"Arun Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/880586fc1e4703d9e951d86655682ffd"},"headline":"Getter Setter in Javascript","datePublished":"2019-12-26T10:26:03+00:00","dateModified":"2019-12-30T09:20:32+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/"},"wordCount":219,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/","url":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/","name":"Getter Setter in Javascript - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png","datePublished":"2019-12-26T10:26:03+00:00","dateModified":"2019-12-30T09:20:32+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/P10.png","width":678,"height":282,"caption":"P10"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/getter-setter-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Getter Setter in Javascript"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/880586fc1e4703d9e951d86655682ffd","name":"Arun Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/22744c127478ae0d9d9efb702c1379e4ae8c5538423ba70bb9a37dfeb92861c9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/22744c127478ae0d9d9efb702c1379e4ae8c5538423ba70bb9a37dfeb92861c9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Arun Kumar"},"url":"https:\/\/webkul.com\/blog\/author\/arun-kumar350\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/217128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/226"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=217128"}],"version-history":[{"count":6,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/217128\/revisions"}],"predecessor-version":[{"id":217991,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/217128\/revisions\/217991"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=217128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=217128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=217128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}