How can JavaScript codes be hidden from old browsers that do not support JavaScript ? Last Updated : 17 Feb, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Nowadays all modern browsers support JavaScript, however, older browsers did not support JavaScript. In this article, we will learn how we can hide JavaScript code from running in older browsers. Approach: After opening the <script> tag, we will use a one-line HTML style comment without any closing character ( <!-- ). We will then write the JavaScript code that is to be hidden from older browsers. We will use the closing character with comment ( //--> ) before we close the script with the </script> tag. Syntax: <script> <!-- // Your JavaScript code // that is hidden from older browser console.log("Hello Geeks"); //--> </script> Example: In this example, the background color will be changed to red if the browser supports JavaScript, else it will remain yellow. HTML <!DOCTYPE html> <html lang="en"> <body bgcolor="yellow"> <h1 style= "text-align: center; font-size: 3rem;"> Hello Geeks </h1> <script type="text/javascript"> <!-- document.bgColor ="red"; //--> </script> </body> </html> Output: We can see that the old browser will ignore JavaScript code and will treat JavaScript code as an HTML comment, but modern browser easily access JavaScript code and will not create any problem. When the browser does not support JavaScript:When the browser supports JavaScript: Note: If the IDE gives a syntax warning using the above approach, we can add a JavaScript comment before the first HTML style comment to prevent it from doing so. <script> //<!-- // Your JavaScript code // that is hidden from older browser console.log("Hello Geeks"); //--> </script> Comment More infoAdvertise with us Next Article How can JavaScript codes be hidden from old browsers that do not support JavaScript ? T torq1284 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to find whether browser supports JavaScript or not ? We will discuss how to find whether our Browser supports JavaScript or not. For this, we need to use the <noscript> tag, which defines an alternate text to be displayed to users who have disabled <script> tag in their Browsers. Since JavaScript is written inside <script> tag in HTM 2 min read How to set alternate content for users that do not support client-side scripts ? In this article, we define an alternate content for users that do not support client-side scripts by using <noscript> tag in the HTML document. It is used to display the text for those browsers that does not support script tag or the browsers disable the script for the user. Syntax: <noscri 1 min read How to detect HTML 5 is supported or not in the browser ? HTML 5 is the latest standard of HTML that includes many new changes and features. HTML 5 support can be detected by using three approaches:Method 1: Checking for Geolocation support: The Geolocation API was added in HTML5. It is used for identifying the user's location. The presence of this API cou 4 min read How to detect browser or tab closing in JavaScript ? Detecting browser or tab closure in JavaScript is essential for preventing data loss or unintended navigation. Using the beforeunload event, developers can prompt users with a confirmation dialog, ensuring they don't accidentally leave a page with unsaved changes or important information. The before 2 min read JavaScript Course Understanding Code Structure in JavaScript Inserting JavaScript into a webpage is much like inserting any other HTML content. The tags used to add JavaScript in HTML are <script> and </script>. The code surrounded by the <script> and </script> tags is called a script blog. The 'type' attribute was the most important a 3 min read Like