If you’re not familiar with JavaScript yet, I’ve been writing about it here that what is JavaScript used for?
In this post, I wanted to talk about what JavaScript is and what you can do with it. Like any programming language, JavaScript’s primary goal is to create a sequence of actions that will result in a certain outcome.
These can be “if-something” conditions, cycles that create a certain sequence of actions, mathematical calculations, etc.
The most important thing is that all these operations can be done on web pages in the browser window. Moreover, JavaScript can work without an Internet connection.
So let’s look at several examples that demonstrate the features you can get with JavaScript. I’ve conditionally sorted them into several groups, so you understand what JavaScript does and why it’s needed.
- Mathematical Operations
- Processing and validating data in HTML forms
- User interactions and events
- Interact with HTML elements on the page and manage their content and styles
Mathematical Operations
Web pages often need to do some calculations. For example, there are two text fields, and you need to deduce the amount of two numbers in the first two in the third text field.
You can use JavaScript to create a calculator and put it on a web page. Here is an example of such a calculator:
Cut and Paste JavaScript-JavaScript calculator
Another situation is to take some text lines on the web page; you need to increase its size by 1.5 times. This can be done with mathematical calculations by multiplying the current size by a factor of 1.5.
Tasks that require computation are very, very much in practice. JavaScript allows you to do all this.
Processing and validating data in HTML forms
JavaScript allows you to check that all the required fields are filled, and the data they contain corresponds to the desired format (for example, if you want numbers, there should be only numbers, and there should be no letters).
Makes this JavaScript without rebooting the page and even without an Internet connection.
Before sending data to the server, they are pre-screened on JavaScript. This reduces the load on the server.
User interactions and events
There may be various effects on the web page, depending on what the user is doing. The drop-down menu on the site when hovering.
When you click on the hide button or show some item on the page. The pop-up appears when the mouse cursor has gone outside the browser window.
The background blackout and the effects of the element’s smooth appearance are implemented on JavaScript.
Interact with HTML elements on the page and manage their content and styles
When a particular event occurs (such as a click or whatever), you can change the items’ appearance (CSS styles) on the page. It’s all done programmatically. You can also add some HTML tags or attributes to them, also when an event occurs.
Conclusion
The possibilities and scope of JavaScript are very extensive. Everything will be limited only to your imagination and creativity.