JavaScript Course Understanding Code Structure in JavaScript Last Updated : 18 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 attribute of <script> tag. However, it is no longer used. The browser understands that <script> tag has JavaScript code inside it.<script>// JavaScript Code</script>Write Structured JavaScript Code: To write a structured JavaScript code right now you have to careful about Statements, Semicolons, and Comments.JavaScript can be added to your HTML file in two waysInternal JavaScriptExternal JavaScriptMethod 1(Internal JavaScript):Create an HTML file(.html) extension and write JavaScript code inside the 'script' tagThen simply load the HTML file in the browserMethod 2(External JavaScript):Create a separate JavaScript file(.js) with .js extension. Write your code in it.Now link this js file with the HTML document using script tag like:<script src='relative_path_to_file/file_name.js'></script>Either in the body or in the head.Let's understand the code structure with the help of a simple JavaScript example that will make a block disappear with javascript only.Code Structure: HTML(index.html):The HTML code contains a simple div element that is wrapped inside an anchor tag(link) so that whenever we click the div element, the javascript code works. Inside the 'div' element there's some random text. Inside the script tag, we are linking the javascript file saved as 'script.js' with the HTML document.CSS(styles.css): The CSS code only targets two elements 'a' and 'div' element whose ID is 'plain'.JavaScript(script.js): The Javascript code is called when we click the 'div' button, as we have linked them with the 'a' tag and also 'onclick='toggle(plain)'. Inside the function, we are passing the 'ID' of the 'div' element and then accessing the element from the 'DOM' using the getElementByID method and then a simple if-else condition which checks if the 'div' is of type 'block' then change the display to none, else change it to display block.Example: Here in this example we have created HTML, CSS and JavaScript file to show the actual directory structure with valid code structure. html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="script.js"></script> <link rel="stylesheet" href="styles.css"> <title>Button Vanisher</title> </head> <body> <a onclick="toggle('plain')"> <div id="plain"> How many times were you frustrated while looking out for a good collection of programming/algorithm/interview questions? What did you expect and what did you get? This portal has been created to provide well written, well thought and well-explained solutions for selected questions. Geeksforgeeks is the one stop solution to all your coding problems! Join us so that we can shape your future. </div> </a> </body> </html> CSS #plain { border: 2px solid black; max-width: 200px; height: 300px; margin: 0 auto; display: block; } a { display: block; } JavaScript // JavaScript function to change the content of the function toggle(id) { let button = document.getElementById(id); if (button.style.display == 'block') { button.style.display = 'none'; } else { button.style.display = 'block'; } } Output Code Explanation:A page is known as a document for the purpose of scripting on a web page.Properties of the document can be referenced by writing the document followed by a dot, followed by the property name. The document has lots of properties.After the <script> tag browser starts to interpret the text as JavaScript until the </script> comes.The above code is a decent example of how we should make a directory, how to link different types of code files with each other, and how to write simple yet effective code. Comment More infoAdvertise with us Next Article JavaScript Course Variables in JavaScript immukul Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Course Similar Reads Introduction to JavaScript Course - Learn how to build a task tracker using JavaScript This is an introductory course about JavaScript that will help you learn about the basics of javascript, to begin with, the dynamic part of web development. You will learn the basics like understanding code structures, loops, objects, etc. What this course is about? In this course we will teach you 4 min read JavaScript Course What is JavaScript ? JavaScript is a very famous programming language that was originally started in the year of 1995 with the motive of making web pages alive. It is also an essential part of the web developer skillset. In simple terms, if you want to learn web development then learn HTML & CSS before starting JavaScri 3 min read JavaScript Hello World The JavaScript Hello World program is a simple tradition used by programmers to learn the new syntax of a programming language. It involves displaying the text "Hello, World!" on the screen. This basic exercise helps you understand how to output text and run simple scripts in a new programming envir 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 JavaScript Course Variables in JavaScript Variables in JavaScript are containers that hold reusable data. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory loca 4 min read JavaScript Data Types In JavaScript, each value has a data type, defining its nature (e.g., Number, String, Boolean) and operations. Data types are categorized into Primitive (e.g., String, Number) and Non-Primitive (e.g., Objects, Arrays).Primitive Data Type1. NumberThe Number data type in JavaScript includes both integ 5 min read JavaScript Course Operators in JavaScript An operator is capable of manipulating a certain value or operand. Operators are used to performing specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands. In JavaScript, operators are used for comparing values, performing arithm 7 min read JavaScript Course Interaction With User Javascript allows us the privilege to which we can interact with the user and respond accordingly. It includes several user-interface functions which help in the interaction. Let's take a look at them one by one. JavaScript Window alert() Method : It simply creates an alert box that may or may not h 2 min read JavaScript Course Logical Operators in JavaScript logical operator is mostly used to make decisions based on conditions specified for the statements. It can also be used to manipulate a boolean or set termination conditions for loops. There are three types of logical operators in Javascript: !(NOT): Converts operator to boolean and returns flipped 3 min read JavaScript Course Conditional Operator in JavaScript JavaScript Conditional Operators allow us to perform different types of actions according to different conditions. We make use of the 'if' statement. if(expression){ do this; } The above argument named 'expression' is basically a condition that we pass into the 'if' and if it returns 'true' then the 3 min read Like