{"id":754,"date":"2017-01-27T16:31:27","date_gmt":"2017-01-27T16:31:27","guid":{"rendered":"http:\/\/scrolltest.com\/?p=754"},"modified":"2017-01-27T16:35:59","modified_gmt":"2017-01-27T16:35:59","slug":"how-to-create-an-objects-in-the-javascript","status":"publish","type":"post","link":"https:\/\/scrolltest.com\/how-to-create-an-objects-in-the-javascript\/","title":{"rendered":"How to create an Object in the Javascript?"},"content":{"rendered":"<p>In this tutorial, We are going to understand what is Object and how we can create Objects in the javascript.<\/p>\n<p><strong>What is Object?<\/strong><br \/>\nAn object is a collection of properties, and a property is an association between a name (or key) and a value. A property&#8217;s value can be a function, in which case the property is known as a method.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft\" src=\"http:\/\/www.freeiconspng.com\/uploads\/coffee-icon-png-29.png\" alt=\"coffe cup\" width=\"154\" height=\"154\" \/><\/p>\n<p>Let&#8217;s take an example, Suppose we have a Coffee cup. It has properties like the blue in color, hot in nature, etc. So let&#8217;s convert this real life object into the computer language.<\/p>\n<p>Open the<a href=\"http:\/\/c9.io\" target=\"_blank\" rel=\"noopener\"> Cloud9 Online\u00a0<\/a>\u00a0Editor . (It&#8217;s a online code editor\u00a0available\u00a0online.).<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<blockquote>\n<pre class=\"theme:monokai lang:js decode:true\">\/\/Start with \r\nvar coffeeObject = {\r\n\r\n};<\/pre>\n<\/blockquote>\n<p><strong>Now we write the properties for it.<\/strong><\/p>\n<pre class=\"theme:monokai lang:js decode:true \">var coffeeObject = {\r\n   color : 'blue',\r\n   plateType : 'Flat',\r\n   isHot : true,\r\n   temperatureInC : '96',\r\n};<\/pre>\n<p>An Object can have method associated, Let&#8217;s have function\/method that can be used to convert the temperature in C to F and attached to our coffeeObject.<\/p>\n<p>[quads id=&#8221;3&#8243;]<\/p>\n<pre class=\"theme:monokai lang:js decode:true \">var coffeeObject  = {\r\n     color  : 'blue',\r\n     plateType : 'Flat',\r\n     isHot : true,\r\n     temperatureInC : '96',\r\n     convertIntoF : function(coffeeObject.temperatureInC){\r\n         console.log('Temperature in C'+coffeeObject.temperatureInC);\r\n         temperatureInF =  coffeeObject.temperatureInC\u00d7 9\/5 + 32;\r\n         console.log('Temperature in F'+temperatureInF);\r\n    \r\n     }\r\n };\r\n \r\n console.log(\"Cofee Mug Color :- \"+ coffeeObject.color);\r\n console.log(\"Cofee plateType  :- \"+ coffeeObject.plateType);\r\n console.log(\"Cofee isHot  :- \"+ coffeeObject.isHot);\r\n \r\n coffeeObject.convertIntoF();\r\n \r\n<\/pre>\n<p>[quads id=&#8221;4&#8243;]<\/p>\n<p><strong>To access the Object key, we have to use the dot pattern. e.g object.key.<\/strong><br \/>\nPlease note you can also access the object key&#8217;s value by<\/p>\n<pre class=\"theme:monokai lang:default decode:true \">console.log(coffeeObject['color']);<\/pre>\n<p>That&#8217;s all folks in the next tutorial we are going to learn more about the object oriented programming in javascript.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-755\" src=\"http:\/\/scrolltest.com\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-27-at-9.52.13-PM.png\" alt=\"code js\" width=\"922\" height=\"556\" srcset=\"https:\/\/scrolltest.com\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-27-at-9.52.13-PM.png 922w, https:\/\/scrolltest.com\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-27-at-9.52.13-PM-300x181.png 300w, https:\/\/scrolltest.com\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-27-at-9.52.13-PM-768x463.png 768w\" sizes=\"auto, (max-width: 922px) 100vw, 922px\" \/><\/p>\n<p>[quads id=&#8221;5&#8243;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, We are going to understand what is Object and how we can create Objects in the javascript. What is Object? An object is a collection of properties, and a property is an association between a name (or key) and a value. A property&#8217;s value can be a function, in which case the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[21],"tags":[37,38],"class_list":["post-754","post","type-post","status-publish","format-standard","hentry","category-js","tag-javascript","tag-oop"],"taxonomy_info":{"category":[{"value":21,"label":"Javascript"}],"post_tag":[{"value":37,"label":"javascript"},{"value":38,"label":"oop"}]},"featured_image_src_large":false,"author_info":{"display_name":"Promode","author_link":"https:\/\/scrolltest.com\/author\/admin\/"},"comment_info":0,"category_info":[{"term_id":21,"name":"Javascript","slug":"js","term_group":0,"term_taxonomy_id":21,"taxonomy":"category","description":"Javascript section","parent":0,"count":15,"filter":"raw","cat_ID":21,"category_count":15,"category_description":"Javascript section","cat_name":"Javascript","category_nicename":"js","category_parent":0}],"tag_info":[{"term_id":37,"name":"javascript","slug":"javascript","term_group":0,"term_taxonomy_id":37,"taxonomy":"post_tag","description":"","parent":0,"count":3,"filter":"raw"},{"term_id":38,"name":"oop","slug":"oop","term_group":0,"term_taxonomy_id":38,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/comments?post=754"}],"version-history":[{"count":0,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/754\/revisions"}],"wp:attachment":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/media?parent=754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/categories?post=754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/tags?post=754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}