{"id":4200,"date":"2023-05-01T05:16:47","date_gmt":"2023-05-01T05:16:47","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=4200"},"modified":"2023-06-10T11:29:39","modified_gmt":"2023-06-10T11:29:39","slug":"react-es6-tutorial-ternary-operator","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/react-es6-tutorial-ternary-operator\/","title":{"rendered":"React &#8211; ES6 Tutorial &#8211; Ternary Operator"},"content":{"rendered":"<h2><em>What is ES6?<\/em><\/h2>\n<p><em>ES6 stands for ECMAScript 6.<\/em><\/p>\n<p><em>ECMAScript was created to standardize JavaScript, and ES6 is the 6th version of ECMAScript, it was published in 2015, and is also known as ECMAScript 2015.<\/em><\/p>\n<h2>Ternary Operator<\/h2>\n<p>The ternary operator is a simplified conditional operator like\u00a0<code class=\"w3-codespan\">if<\/code>\u00a0\/\u00a0<code class=\"w3-codespan\">else<\/code>.<\/p>\n<p>Syntax:\u00a0<code class=\"w3-codespan\">condition ? &lt;expression if true&gt; : &lt;expression if false&gt;<\/code><\/p>\n<p>Here is an example using\u00a0<code class=\"w3-codespan\">if<\/code>\u00a0\/\u00a0<code class=\"w3-codespan\">else<\/code>:<\/p>\n<h3>Example<\/h3>\n<p>Before:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">if (authenticated) {\r\n  renderApp();\r\n} else {\r\n  renderLogin();\r\n}<\/pre>\n<p>Here is the same example using a ternary operator:<\/p>\n<div class=\"w3-example\">\n<h3>Example<\/h3>\n<p>With Ternary<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">authenticated ? renderApp() : renderLogin();<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is ES6? ES6 stands for ECMAScript 6. ECMAScript was created to <a class=\"read-more\" href=\"https:\/\/rengga.dev\/blog\/react-es6-tutorial-ternary-operator\/\" title=\"React &#8211; ES6 Tutorial &#8211; Ternary Operator\" itemprop=\"url\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":4376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"quote","meta":{"footnotes":""},"categories":[508,12],"tags":[516,514,517,511,510,491,519,509,513,512,518,520,515],"newstopic":[578],"class_list":{"0":"post-4200","1":"post","2":"type-post","3":"status-publish","4":"format-quote","5":"has-post-thumbnail","7":"category-react","8":"category-web-development","9":"tag-array-methods","10":"tag-arrow-functions","11":"tag-destructuring","12":"tag-ecmascript-6","13":"tag-es6-tutorial","14":"tag-javascript","15":"tag-modules","16":"tag-react","17":"tag-react-classes","18":"tag-react-tutorial","19":"tag-spread-operator","20":"tag-ternary-operator","21":"tag-variables","22":"post_format-post-format-quote","23":"newstopic-react"},"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=4200"}],"version-history":[{"count":1,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4200\/revisions"}],"predecessor-version":[{"id":4202,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4200\/revisions\/4202"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/4376"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=4200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=4200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=4200"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=4200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}