Tutorial 2 - Introduction To JavaScript (Part 2)
Tutorial 2 - Introduction To JavaScript (Part 2)
7. Strings
8. Arrays
9. Functions
Anywhere in your application, you may call a function, which is a collection of
reusable code. This avoids the need to repeatedly write the same code.
Programmers can use it to write modular programs. A programmer can break up a
large program into several smaller, more manageable components using functions.
The characteristics required to construct modular code using functions are
supported by JavaScript, just like they are by any other advanced programming
language. We may also create our own functions in JavaScript.
10. Events
Events that happen when a user or browser modifies a page are used to handle
JavaScript's interaction with HTML.
An event occurs when the page loaded. A button click by the user also counts as an
event. Other instances consist of actions like shutting a window, changing the size
of a window, etc.
Developers may utilize these events to run JavaScript programmed replies that,
among other things, cause buttons to shut windows, users to see messages, data to
be verified, and just about any other reaction conceivable.
Events are components of the Document Object Model (DOM) Level 3 and are
present in every HTML element. These events may be used to execute JavaScript
code.
Common HTML Events
Event Description
onchange Triggers when an element changes
onclick Triggers on a mouse click
onmouseover Triggers when the mouse pointer moves over an element
onmouseout Triggers when the mouse pointer moves out of an element
onkeydown Triggers when a key is pressed
onload Triggers when the document loads
There are also many other events, you should take a look at the list of HTML
DOM Events from W3School to get more details and try them if possible:
https://www.w3schools.com/jsref/dom_obj_event.asp
a) onclick Event Type Example
b) onsubmit Event Type Example
Before forwarding site visitors to a new page, you might display a suitable
message to them. To load a new page, there would be a small wait. The way to
accomplish the same is demonstrated in the example below. Here, the built-in
JavaScript method setTimeout() may be used to call another function after a
predetermined amount of time.
12. Dialog Boxes
a) Alert Dialog Box
b) Confirmation Dialog Box
c) Prompt Dialog Box
13. Page Printing
You might want to include a button on your website that allows users to print the
page's contents using a real printer. Using the print method of the window object,
JavaScript facilitates the implementation of this feature.
The current web page is printed when the JavaScript print method window.print()
is used. As seen in the following example, you may call this method directly using
the onclick event.
14. Advance JavaScript (for reference)
There are many more advance topics with JavaScript, which you can explore
yourself through internet. In this part, there are some suggestions maybe helpful
for you to get well with JavaScript:
https://fullstack.edu.vn/courses/javascript-co-ban (Highly recommend)
https://www.programiz.com/javascript (Highly recommend)
https://www.tutorialspoint.com/javascript/index.htm
https://www.w3schools.com/js/default.asp
https://www.javatpoint.com/javascript-tutorial
https://www.youtube.com/watch?v=PkZNo7MFNFg
https://www.youtube.com/watch?v=W6NZfCO5SIk