Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to JavaScript Code

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will give you a detailed introduction to the JavaScript code. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

JavaScript was founded 26 years ago and is currently one of the most popular programming languages. But what is JavaScript? JavaScript is used with HTML and CSS to create dynamic and interactive web pages and mobile applications. We often call it one of the building blocks developed by Web.

According to W3Techs,

97.6% of the websites use JavaScript as the client programming language. History of JavaScript

In 1995, Netscape developer Brendan Eich created the first version of JavaScript in just 10 days. When I first came out, it was called Mocha, then it was changed to LiveScript, and finally I chose JavaScript.

The boss of Brendan Eich wants JavaScript to have a syntax similar to Java. They also believe that JavaScript will help speed up Web development and make it easier to learn than Java.

However, in fact, the relationship between JavaScript and java is like Lei Feng and Lei Feng Pagoda, with no similarities except for their similar names.

Over the years, JavaScript has evolved into a versatile language that can be used in Web and mobile applications.

What is ECMAScript?

ECMAScript represents the script of the European Association of computer Manufacturers. According to the MDN documentation

ECMAScript is the scripting language that forms the basis of JavaScript.

The association created the ECMA standard to ensure that web pages are consistent across browsers. As of August 2021, there were 12 released versions of ECMAScript.

Is Java the same as JavaScript?

Although the two languages have similar syntax and share the first four letters of "Java", they are not the same language.

Here are some of the main differences between the two languages.

Java is a compiled programming language. This means that before the program runs, the code needs to be translated into machine code so that the computer can understand it.

JavaScript is an interpretive language. In the browser, the interpreter will read the substitution code and run it without compiling it first.

Java is used as a server-side (back-end) language, while JavaScript is mainly used as a client (front-end) language. But JavaScript can also be used to create back-end Web applications using Node.js.

How do HTML, CSS, and JavaScript work together on a web page?

Now that we know the history of JavaScript, we need to understand how it works on the website.

HTML renders the content, CSS sets the page style to make it look good, and JavaScript makes the site interactive. But what does interaction mean and how does JavaScript work with the other two languages?

Let's look at an example to better understand how the three languages work together.

In this example, when the user clicks the button, a message is displayed containing the number of times the user clicked. When the count reaches a certain threshold, the message changes and becomes more obvious as the count increases.

We use HTML to create and display buttons on the page.

Click me

We also have this element in the HTML of p, which has no text between the opening and closing tags. In JavaScript, text is added as soon as the user clicks the button.

We use CSS to style the button and place it in the center of the page.

Button {display: block; margin: 20px auto 10px; padding: 25px 20px; font-size: 1.4remt; cursor: pointer; border: none; border-radius: 50%; background-color: # 3b5998; color: white;}

To access the HTML element, we use getElementById. This is the opportunity for our JavaScript to display its talents.

Const btn = document.getElementById ("btn"); const para = document.getElementById ("para")

The called variable count tracks the number of times the user clicks the button. The count is constantly updated each time the button is clicked.

Let count = 0

This is the array of responses that will be displayed to the user.

Const responsesArr = ["You have clicked the button this many times:", "Wow, you like to click that button. Button clicks:", "Why do you keep clicking it? Button clicks:", "Now you are just being annoying. Button clicks:"]

We use addEventListener which tells the computer to listen for click events. When a click is detected, a message with a count is displayed on the screen.

Btn.addEventListener ("click", () = > {count++; if (count)

< 10) { para[xss_clean] = `${responsesArr[0]} ${count}`; } else if (count >

= 10 & & count

< 15) { para[xss_clean] = `${responsesArr[1]} ${count}`; } else if (count >

= 15 & & count < 20) {else [XSS _ clean] = `${responsesArr [2]} ${count}`;} else {paraa [XSS _ clean] = `${responsesArr [3]} ${count}`;}})

We use an if else statement to check how many times the button has been clicked and display different messages based on the number of counts.

If the count is less than 10, this is the message displayed on the screen.

If the count is between 10 and 14, this is the message displayed on the screen.

If the count is between 15 and 19, this is the message displayed on the screen.

If the count is 20 or greater, this is the message displayed on the screen.

How to start learning JavaScript

This is a list of important resources where you can start learning about JavaScript.

JavaScript tutorial

JavaScript and HTML DOM reference manuals

TypeScript tutorial

ES6 Chinese course

HTML DOM tutorial

JavaScript libraries and frameworks

JavaScript libraries and frameworks are designed to help speed up development. Once you have learned "Vanilla" (or basic / normal) JavaScript, you can start learning a library or framework.

There are many options to choose from, but you don't need to learn all of them. Study the recruitment information in your area to find out which libraries and frameworks are being used.

Here are some popular options.

React

Angular

Vue

Conclusion

JavaScript was first founded in 1995 and has since become a powerful and versatile language for websites, online games, and mobile applications.

Although Java and JavaScript have similar syntax and share the first four letters of "Java", they are not the same language. Java is mainly used as a server-side language, while JavaScript is used for browsers.

HTML, CSS and JavaScript are the three core languages of Web. HTML is used for content, CSS for style, and JavaScript for interaction on the site.

This is the end of this article on "introduction to JavaScript Code". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report