Home >Web Front-end >Front-end Q&A >How to use javascript in web pages
With the development of the Internet, the interactivity of web pages is becoming more and more important, and JavaScript is a very useful programming language. It can make web pages more interactive between users and web pages, thereby improving user experience. . So, how to use JavaScript in web pages? This article will introduce it from the following aspects.
1. Basic syntax of JavaScript
Before using JavaScript, we need to understand some of its basic syntax. Similar to other programming languages, JavaScript also has basic syntax such as variables, loops, and functions. For example:
//Define variable var name = "John"; //Define function sayHello(name) { console.log("Hello " name "!"); } //Loop for (var i = 0; i < 10; i ) { console.log(i); }
2. Embedding JavaScript in HTML files
When embedding JavaScript in HTML files, we need to use <script> tag. For example: </p> <p><!DOCTYPE html> <html> <head> <title>My Page</title> </head> <body> <h1>Hello World!< /h1> <script> console.log("Hello World!"); </script>