{"id":30565,"date":"2023-01-15T15:56:22","date_gmt":"2023-01-15T10:26:22","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/"},"modified":"2023-01-15T15:56:22","modified_gmt":"2023-01-15T10:26:22","slug":"solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/","title":{"rendered":"[Solved] Has something changed in Javascript implementations recently (or is it me)?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-27396084\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"27396084\" data-parentid=\"27396041\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>No, this hasn&#8217;t changed (there&#8217;s something <em>similar<\/em> that&#8217;s changed, but not this; more below). Here&#8217;s the difference: If <code>item<\/code> isn&#8217;t <em>declared<\/em>, then you&#8217;ll get the error about <code>item<\/code>. If <code>item<\/code> is declared but has the value <code>undefined<\/code>, you&#8217;ll get the error about reading a property of <code>undefined<\/code>. This has always been the case.<\/p>\n<p>You mentioned Firefox. Firefox&#8217;s error messages for these two different conditions are confusingly similar. If the variable is <em>undeclared<\/em>, it says:<\/p>\n<pre>ReferenceError: item is not defined<\/pre>\n<p>But if the variable is declared and has the value <code>undefined<\/code>, it says:<\/p>\n<pre>TypeError: item is undefined<\/pre>\n<p>Note the difference, but the <em>extreme<\/em> similarity. I would say Firefox&#8217;s error messages are poor in this regard. Chrome&#8217;s are more clearly distinct:<\/p>\n<pre>ReferenceError: item is not defined\nTypeError: Cannot read property 'property' of undefined<\/pre>\n<p>But that&#8217;s just the error message. The underyling issue, trying to read the value of an undeclared symbol, has always been an error.<\/p>\n<p>Re the two answers you linked to: I&#8217;m sorry, but they were always wrong <em>for the undeclared case<\/em> (and right for the <code>undefined<\/code> case), this is just something that people don&#8217;t understand well. If <code>item<\/code> may be <em>completely undeclared<\/em>, you can&#8217;t use that idiom. You <em>can<\/em> use <code>typeof<\/code>, though:<\/p>\n<pre><code>if (typeof item !== \"undefined\" &amp;&amp; item.property)\n<\/code><\/pre>\n<p><code>typeof<\/code> is fine with undeclared symbols, but reading the value of an undeclared symbol is an error, as has been for as long as we&#8217;ve had JavaScript.<\/p>\n<p>Here&#8217;s a question from 2011 about this. The accepted answer with a score of 1,016 talks about <code>typeof<\/code>.<\/p>\n<p>Here are examples of both cases:<\/p>\n<h3>Undeclared:<\/h3>\n<\/p>\n<div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"false\" data-babel=\"false\">\n<div class=\"snippet-code\">\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code>\/\/ Note that `item` isn't declared anywhere at all\r\ntry {\r\n  if (item.property) {\r\n    snippet.log(\"true\");\r\n  }\r\n}\r\ncatch (e) {\r\n  snippet.log((e.name || \"Exception\") + \": \" + (e.message || String(e)));\r\n}<\/code><\/pre>\n<pre class=\"snippet-code-html lang-html prettyprint-override\"><code>&lt;!-- Script provides the `snippet` object, see http:\/\/meta.stackexchange.com\/a\/242144\/134069 --&gt;\r\n&lt;script src=\"http:\/\/tjcrowder.github.io\/simple-snippets-console\/snippet.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<\/div>\n<\/div>\n<h3>Declared but has the value <code>undefined<\/code>:<\/h3>\n<\/p>\n<div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"false\" data-babel=\"false\">\n<div class=\"snippet-code\">\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code>var item;\r\ntry {\r\n  if (item.property) {\r\n    snippet.log(\"true\");\r\n  }\r\n}\r\ncatch (e) {\r\n  snippet.log((e.name || \"Exception\") + \": \" + (e.message || String(e)));\r\n}<\/code><\/pre>\n<pre class=\"snippet-code-html lang-html prettyprint-override\"><code>&lt;!-- Script provides the `snippet` object, see http:\/\/meta.stackexchange.com\/a\/242144\/134069 --&gt;\r\n&lt;script src=\"http:\/\/tjcrowder.github.io\/simple-snippets-console\/snippet.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<\/div>\n<\/div>\n<p>The similar thing that&#8217;s changed is how <em>assigning<\/em> to something that isn&#8217;t declared at all is handled:<\/p>\n<pre><code>item = \"foo\";\n<\/code><\/pre>\n<p>In loose mode, that&#8217;s an <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/blog.niftysnippets.org\/2008\/03\/horror-of-implicit-globals.html\"><em>implicit global variable<\/em><\/a>, even if the assignment is inside a function. In ES5&#8217;s strict mode, though, it&#8217;s an error.<\/p>\n<p>But that doesn&#8217;t relate to <em>reading<\/em> the value of an undeclared variable, which was always an error, just <em>writing<\/em> to it.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Has something changed in Javascript implementations recently (or is it me)? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] No, this hasn&#8217;t changed (there&#8217;s something similar that&#8217;s changed, but not this; more below). Here&#8217;s the difference: If item isn&#8217;t declared, then you&#8217;ll get the error about item. If item is declared but has the value undefined, you&#8217;ll get the error about reading a property of undefined. This has always been the case. You &#8230; <a title=\"[Solved] Has something changed in Javascript implementations recently (or is it me)?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\" aria-label=\"More on [Solved] Has something changed in Javascript implementations recently (or is it me)?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[333],"class_list":["post-30565","post","type-post","status-publish","format-standard","hentry","category-solved","tag-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Has something changed in Javascript implementations recently (or is it me)? - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Has something changed in Javascript implementations recently (or is it me)? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] No, this hasn&#8217;t changed (there&#8217;s something similar that&#8217;s changed, but not this; more below). Here&#8217;s the difference: If item isn&#8217;t declared, then you&#8217;ll get the error about item. If item is declared but has the value undefined, you&#8217;ll get the error about reading a property of undefined. This has always been the case. You ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-15T10:26:22+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\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:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Has something changed in Javascript implementations recently (or is it me)?\",\"datePublished\":\"2023-01-15T10:26:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\"},\"wordCount\":336,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"javascript\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\",\"name\":\"[Solved] Has something changed in Javascript implementations recently (or is it me)? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-01-15T10:26:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Has something changed in Javascript implementations recently (or is it me)?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Has something changed in Javascript implementations recently (or is it me)? - JassWeb","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:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Has something changed in Javascript implementations recently (or is it me)? - JassWeb","og_description":"[ad_1] No, this hasn&#8217;t changed (there&#8217;s something similar that&#8217;s changed, but not this; more below). Here&#8217;s the difference: If item isn&#8217;t declared, then you&#8217;ll get the error about item. If item is declared but has the value undefined, you&#8217;ll get the error about reading a property of undefined. This has always been the case. You ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/","og_site_name":"JassWeb","article_published_time":"2023-01-15T10:26:22+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Has something changed in Javascript implementations recently (or is it me)?","datePublished":"2023-01-15T10:26:22+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/"},"wordCount":336,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["javascript"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/","url":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/","name":"[Solved] Has something changed in Javascript implementations recently (or is it me)? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-15T10:26:22+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-has-something-changed-in-javascript-implementations-recently-or-is-it-me\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Has something changed in Javascript implementations recently (or is it me)?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=30565"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30565\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=30565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=30565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=30565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}