{"id":7268,"date":"2021-08-02T12:30:54","date_gmt":"2021-08-02T12:30:54","guid":{"rendered":"https:\/\/www.scmgalaxy.com\/tutorials\/?p=7268"},"modified":"2022-04-13T16:30:47","modified_gmt":"2022-04-13T16:30:47","slug":"typeof-operator-in-javascripts","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/","title":{"rendered":"Typeof operator in JavaScripts"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The typeof operator is used to get the data type (returns a string) of its operand. The operand can be either a literal or a data structure such as a variable, a function, or an object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Syntax: &#8211;<br>typeof operand<br>typeof(operand)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ex: &#8211;<br>typeof \u201ca\u201d;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Undefined<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The undefined type is used for variable or object properties that either do not exist or have not been assigned a value. The only value an undefined type can have is <em>undefined<\/em>.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/5408ff76eae9503738ffb0c99bdce901.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Null<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The null value indicates an empty value; it is essentially a placeholder that represents \u201cnothing\u201d. The null value is defined as an empty object so using typeof operator on a variable holding null shows its type to be an object.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/3b8810255f257ca72da73faf3c4ee6a5.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Undefined Vs Null<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Undefined means the value hasn\u201ft been set, whereas null means the value has been set to be empty.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">var, let and const<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>var &#8211;<\/strong> The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for variables declared outside any function, global.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>let &#8211;<\/strong> let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>const &#8211; <\/strong>This declaration creates a constant whose scope can be either global or local to the block in which it is declared. Global constants do not become properties of the window object, unlike var variables. An initializer for a constant is required; that is, you must specify its value in the same statement in which it&#8217;s declared which can&#8217;t be changed later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The typeof operator is used to get the data type (returns a string) of its operand. The operand can be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[16],"tags":[5095,5331,5595,5814,5815],"class_list":["post-7268","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-javascript","tag-null-safety","tag-operators-in-php","tag-typeof","tag-undefined"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Typeof operator in JavaScripts - scmGalaxy<\/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:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Typeof operator in JavaScripts - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"The typeof operator is used to get the data type (returns a string) of its operand. The operand can be [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-02T12:30:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-13T16:30:47+00:00\" \/>\n<meta name=\"author\" content=\"rajeshkumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rajeshkumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/\"},\"author\":{\"name\":\"rajeshkumar\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\"},\"headline\":\"Typeof operator in JavaScripts\",\"datePublished\":\"2021-08-02T12:30:54+00:00\",\"dateModified\":\"2022-04-13T16:30:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/\"},\"wordCount\":265,\"commentCount\":0,\"keywords\":[\"Javascript\",\"null safety\",\"Operators in PHP\",\"typeof\",\"Undefined\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/\",\"name\":\"Typeof operator in JavaScripts - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-08-02T12:30:54+00:00\",\"dateModified\":\"2022-04-13T16:30:47+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/typeof-operator-in-javascripts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Typeof operator in JavaScripts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\",\"name\":\"rajeshkumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"caption\":\"rajeshkumar\"},\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/rajeshkumar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Typeof operator in JavaScripts - scmGalaxy","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:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/","og_locale":"en_US","og_type":"article","og_title":"Typeof operator in JavaScripts - scmGalaxy","og_description":"The typeof operator is used to get the data type (returns a string) of its operand. The operand can be [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/","og_site_name":"scmGalaxy","article_published_time":"2021-08-02T12:30:54+00:00","article_modified_time":"2022-04-13T16:30:47+00:00","author":"rajeshkumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rajeshkumar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/"},"author":{"name":"rajeshkumar","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361"},"headline":"Typeof operator in JavaScripts","datePublished":"2021-08-02T12:30:54+00:00","dateModified":"2022-04-13T16:30:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/"},"wordCount":265,"commentCount":0,"keywords":["Javascript","null safety","Operators in PHP","typeof","Undefined"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/","name":"Typeof operator in JavaScripts - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-08-02T12:30:54+00:00","dateModified":"2022-04-13T16:30:47+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/typeof-operator-in-javascripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Typeof operator in JavaScripts"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361","name":"rajeshkumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","caption":"rajeshkumar"},"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/rajeshkumar\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/7268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=7268"}],"version-history":[{"count":2,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/7268\/revisions"}],"predecessor-version":[{"id":7276,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/7268\/revisions\/7276"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=7268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=7268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=7268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}