<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":3976,"date":"2022-03-22T07:39:47","date_gmt":"2022-03-22T07:39:47","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=3976"},"modified":"2022-03-29T12:08:52","modified_gmt":"2022-03-29T12:08:52","slug":"how-to-write-comments-in-reactjs","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/","title":{"rendered":"How to write comments in ReactJS ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\"><strong>ReactJS\u00a0<\/strong>is a JS library used for building user interfaces.<\/li>\n<li style=\"text-align: justify;\">It is Declarative, Component-based and Technology stack agnostic.<\/li>\n<li style=\"text-align: justify;\">It is only designed for speed, simplicity, and scalability.<\/li>\n<li style=\"text-align: justify;\">It is some of the most popular libraries among web developers.<\/li>\n<\/ul>\n<p><strong>For example(1),<\/strong><\/p>\n<p><strong>Comments for React Components: <\/strong><\/p>\n<ul>\n<li>We can write comments in React using the double forward-slash <strong>\/\/<\/strong> or the asterisk format <strong>\/* *\/<\/strong>, similar to regular JavaScript.<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">import React, { Component } from &#039;react&#039;;<br\/>  <br\/>\/\/ This is a comment<br\/>  <br\/>class App extends Component {<br\/>  <br\/>    \/* This is <br\/>    also a comment*\/<br\/>    render() {<br\/>        return (<br\/>            &lt;div&gt;<br\/>                &lt;h1&gt;Welcome to Kaashiv&lt;\/h1&gt;<br\/>            &lt;\/div&gt;<br\/>        );<br\/>    }<br\/>}<br\/>  <br\/>export default App;<\/code><\/pre> <\/div>\n<p><strong>Output :<\/strong><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"img-responsive aligncenter wp-image-3977 size-full\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png\" alt=\"\" width=\"1563\" height=\"764\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png 1563w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-300x147.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1024x501.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-768x375.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1536x751.png 1536w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-390x191.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-820x401.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1180x577.png 1180w\" sizes=\"(max-width: 1563px) 100vw, 1563px\" \/><\/p>\n<p><strong>For example(2),<\/strong><\/p>\n<p>In example(1) does not work when we want to comment on things inside the <strong>render block<\/strong>. we use JSX inside the render block and must use the multi-line comments in curly braces <strong>{\/* *\/} <\/strong>.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">import React, { Component } from &#039;react&#039;;<br\/>  <br\/>class App extends Component {<br\/>    render() {<br\/>        return (      <br\/>            &lt;div&gt;<br\/>                \/\/ This is not a valid comment<br\/>                \/* Neither is this *\/<br\/>  <br\/>                { \/* THIS ONE IS A VALID COMMENT *\/ }<br\/>}<br\/>                  <br\/>                &lt;h1&gt;Welcome to Kaashiv&lt;\/h1&gt;<br\/>            &lt;\/div&gt;<br\/>        );<br\/>    }<br\/>}<br\/>  <br\/>export default App; <\/code><\/pre> <\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-3978 size-full\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1.png\" alt=\"\" width=\"1489\" height=\"727\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1.png 1489w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1-300x146.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1-1024x500.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1-768x375.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1-390x190.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1-820x400.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv-1-1180x576.png 1180w\" sizes=\"(max-width: 1489px) 100vw, 1489px\" \/><\/p>\n<p><strong>For example(3),<\/strong><\/p>\n<p>We must remember, that even though JSX gets rendered just like normal HTML. It is actually a syntax extension to JavaScript. So, using <strong>&lt;!\u2013 \u2013&gt;<\/strong> as we did with <strong>HTML and XML<\/strong> will not work.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">import React, { Component } from &#039;react&#039;;<br\/>  <br\/>class App extends Component {<br\/>    render() {<br\/>        return (     <br\/>            &lt;div&gt;<br\/>                &lt;!-- This is not a valid comment --&gt;<br\/>                  <br\/>                {\/* THIS ONE IS A VALID COMMENT *\/}<br\/>                  <br\/>                &lt;h1&gt;Welcome to Kaashiv&lt;\/h1&gt;<br\/>            &lt;\/div&gt;<br\/>        );<br\/>    }<br\/>}<br\/>  <br\/>export default App;<\/code><\/pre> <\/div>\n<p><strong>Output:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4038\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/failed-to-compile.png\" alt=\"\" width=\"903\" height=\"323\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/failed-to-compile.png 903w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/failed-to-compile-300x107.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/failed-to-compile-768x275.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/failed-to-compile-390x140.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/failed-to-compile-820x293.png 820w\" sizes=\"(max-width: 903px) 100vw, 903px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic. It is only designed for speed, simplicity, and scalability. It is some of the most popular libraries among web developers. For example(1), Comments for React Components: We can write comments in React using the double forward-slash \/\/ or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[16542],"tags":[16686,16687,16685,16692,16682,16691,16681,16683,16694,16680,16688,16693,16690,16684,16689],"class_list":["post-3976","post","type-post","status-publish","format-standard","hentry","category-reactjs","tag-comment-in-react-code-example","tag-comments-in-jsx","tag-comments-list-reactjs-code-example","tag-how-to-comment-in-react-js-shortcut","tag-how-to-comment-in-react-jsx","tag-how-to-comment-react-code-in-vscode","tag-how-to-use-comments-in-react","tag-how-to-write-comments-in-react-and-jsx","tag-how-to-write-comments-in-react-js","tag-how-to-write-comments-in-reactjs","tag-react-comment-reply-component","tag-react-commenting-best-practices","tag-react-comments-npm","tag-react-native-comments","tag-single-line-comment-in-react-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to write comments in ReactJS ? - React Interview Questions<\/title>\n<meta name=\"description\" content=\"How to write comments in ReactJS ? - ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic.\" \/>\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.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to write comments in ReactJS ? - React Interview Questions\" \/>\n<meta property=\"og:description\" content=\"How to write comments in ReactJS ? - ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-22T07:39:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-29T12:08:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/\",\"name\":\"How to write comments in ReactJS ? - React Interview Questions\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png\",\"datePublished\":\"2022-03-22T07:39:47+00:00\",\"dateModified\":\"2022-03-29T12:08:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"How to write comments in ReactJS ? - ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png\",\"width\":1563,\"height\":764},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to write comments in ReactJS ? - React Interview Questions","description":"How to write comments in ReactJS ? - ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic.","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.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/","og_locale":"en_US","og_type":"article","og_title":"How to write comments in ReactJS ? - React Interview Questions","og_description":"How to write comments in ReactJS ? - ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/","og_site_name":"Wikitechy","article_published_time":"2022-03-22T07:39:47+00:00","article_modified_time":"2022-03-29T12:08:52+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/","name":"How to write comments in ReactJS ? - React Interview Questions","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png","datePublished":"2022-03-22T07:39:47+00:00","dateModified":"2022-03-29T12:08:52+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"How to write comments in ReactJS ? - ReactJS\u00a0is a JS library used for building user interfaces. It is Declarative, Component-based and Technology stack agnostic.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/how-to-write-comments-in-reactjs\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/welcome-to-kaashiv.png","width":1563,"height":764},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/3976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=3976"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/3976\/revisions"}],"predecessor-version":[{"id":4039,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/3976\/revisions\/4039"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=3976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=3976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=3976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}