Professional Documents
Culture Documents
University of Anbar
College of Computer Science and
Information Technology
Introduction:
JavaScript is a dynamic computer programming language. It is lightweight and
most commonly used as a part of web pages, whose implementations allow
client-side script to interact with the user and make dynamic pages.
JavaScript was first known as LiveScript, but Netscape changed its name to
JavaScript made its first appearance in Netscape 2.0 in 1995 with the name
LiveScript. The general-purpose core of the language has been embedded in
Netscape, Internet Explorer, and other web browsers.
language.
It means that a web page need not be a static HTML, but can include programs that
interact with the user, control the browser, and dynamically create HTML content.
The JavaScript code is executed when the user submits the form, and only if all the
entries are valid, they would be submitted to the Web Server. JavaScript can be
used to trap user-initiated events such as button clicks, link navigation, and other
actions that the user initiates explicitly or implicitly[1]
Server-side code on the other hand is run on the server, then its results are
downloaded and displayed in the browser. Examples of popular server-side web
languages include PHP, Python, Ruby, ASP.NET and... JavaScript! JavaScript can
also be used as a server-side language, for example in the popular Node.js
environment you can find out more about server-side JavaScript in our Dynamic
Websites.[2]
The tasks you perform:
The core client-side JavaScript language consists of some common programming
features that allow you to do things like:
Store useful values inside variables. In the above example for instance, we ask for
a new name to be entered then store that name in a variable called name.
What is even more exciting however is the functionality built on top of the client-
side JavaScript language. So-called Application Programming Interfaces (APIs)
provide you with extra superpowers to use in your JavaScript code.[2]
Compiled languages on the other hand are transformed (compiled) into another
form before they are run by the computer. For example, C/C++ are compiled into
machine code that is then run by the computer. The program is executed from a
binary format, which was generated from the original program source code.
JavaScript is a lightweight interpreted programming language. The web browser
receives the JavaScript code in its original text form and runs the script from that.
From a technical standpoint, most modern JavaScript interpreters actually use a
technique called just-in-time compiling to improve performance; the JavaScript
source code gets compiled into a faster, binary format while the script is being
used, so that it can be run as quickly as possible. However, JavaScript is still
considered an interpreted language, since the compilation is handled at run time,
rather than ahead of time.[2]
*There are advantages to both types of language, but we won't discuss them right
now.
Advantages of JavaScript:
The merits of using JavaScript are:
Less server interaction: You can validate user input before sending the page
off to the server. This saves server traffic, which means less load on your
server.
Immediate feedback to the visitors: They don't have to wait for a page
reload to see if they have forgotten to enter something.
Increased interactivity: You can create interfaces that react when the user
hovers over them with a mouse or activates them via the keyboard.
Richer interfaces: You can use JavaScript to include such items as
Client-side JavaScript does not allow the reading or writing of files. This has
been kept for security reason.
JavaScript cannot be used for networking applications because there is no
such support available.
JavaScript doesn't have any multithreading or multiprocessor capabilities.
allows you to build interactivity into otherwise static HTML pages. [2]
You can place the <script> tags, containing your JavaScript, anywhere within you
web page, but it is normally recommended that you should keep it within the
<head>
tags.
The <script> tag alerts the browser program to start interpreting all the text
between
these tags as a script. A simple syntax of your JavaScript will appear as follows.
<script ...>
JavaScript code
</script>
The script tag takes two important attributes:
Language: This attribute specifies what scripting language you are using.
Typically, its value will be javascript. Although recent versions of HTML
(and
XHTML, its successor) have phased out the use of this attribute.
Type: This attribute is what is now recommended to indicate the scripting
language in use and its value should be set to "text/javascript".
JavaScript code
</script>
JavaScript is the world’s most popular programming language:
It’s no news to anyone that JavaScript is incredibly popular these days. Stack
Overflow’s 2018 developer survey has JavaScript as the most popular
programming language (with fellow web languages HTML and CSS). GitHub’s
most recent Octoverse infographic ranks languages by the number of pull requests
received, and JavaScript is the top there, too.
1-Internal JavaScript
First of all, make a local copy of our example file apply-javascript.html. Save it in
a directory somewhere sensible.
Open the file in your web browser and in your text editor. You'll see that the
HTML creates a simple web page containing a clickable button.
Next, go to your text editor and add the following in your head — just before your
closing </head> tag:
<script>
</script>
2-External JavaScript
This works great, but what if we wanted to put our JavaScript in an external file?
Let's explore this now.
1.First, create a new file in the same directory as your sample HTML file. Call it
script.js — make sure it has that .js filename extension, as that's how it is
recognized as JavaScript.
4.Save and refresh your browser, and you should see the same thing! It works just
the same, but now we've got our JavaScript in an external file. This is generally a
good thing in terms of organizing your code and making it reusable across multiple
HTML files. Plus, the HTML is easier to read without huge chunks of script
dumped in it.[2]
Note that sometimes you'll come across bits of actual JavaScript code living inside
HTML. It might look something like this:
function createParagraph() {
document.body.appendChild(para);
the same functionality as in the previous two sections, except that the <button>
element includes an inline onclick handler to make the function run when the
button is pressed.[4]
Conclusion:
JavaScript is a scripting or programming language that allows you to implement
complex features on web pages every time a web page does more than just sit there
and display static information for you to look at displaying timely content updates,
interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. you
can bet that JavaScript is probably involved. It is the third layer of the layer cake of
standard web technologies, two of which (HTML and CSS) we have covered in
much more detail in other parts of the Learning Area.[2]
References:
1-https://www.tutorialspoint.com/javascript/
2-https://developer.mozilla.org/en-
US/docs/Learn/JavaScript/First_steps/What_is_JavaScript
3-https://medium.com/npm-inc/this-year-in-javascript-2018-in-review-and-npms-
predictions-for-2019-3a3d7e5298ef
4-https://www.w3schools.com/js/js_whereto.asp