Computer Skills for Research

Scripting in JavaScript

By

First published on October 10, 2019. Last updated on February 16, 2020.


Javascript is a scripting language that is executed in web pages. Javascript is responsible for much of the interactivity you encounter in webpages. Javascript can manipulate many of the objects in a web page. Javascript can be included directly in html files, or it can be in its own file and referenced by the html file.

Let’s explore a simple script included in an html page. Below is some HTML code for a button, followed by some Javascript code. Clicking the button will pop up an alert window displaying “Hello!”

<button onclick="myPopupBox()">Click here</button>   

<script> 
    function myPopupBox() { alert("Hello!");} 
</script>

Javascript can use variables and functions, so it behaves much as other programming languages. Generally, Javascript must be enclosed in script tags.

Javascript can write to an alert window, to a web page, or to specific elements in a web page.

Libraries

Many of the advanced interactive or visualization effects that you encounter in web pages are created using Javascript libaries. These are collections of special, custom-written Javascript functions bundled together. Examples include JQuery, NodeJS and D3.

Resources


COURSE


Content is copyright the author. Layout is copyright Mark Ciotola. See Corsbook.com for further notices.