📙
Workbook - Introduction to Software Systems
  • About - Workbook
  • Introduction
  • Software Engineering
    • Software Systems
    • Software Product Development
    • Networking
  • TERMINAL PROGRAMMING
    • LINUX - SHELL
    • Practice Questions
  • Web Technologies
    • HTML
    • CSS
    • JavaScript
  • Databases
    • Database Systems
    • SQL - CURD Operations
  • Object Oriented Programming
    • Python
  • Lab Activities
    • Understanding GIT - Lab 1
    • SHELL - Lab 2
      • Class Quiz (15/6/2021)
      • Class Test Script
      • SHELL Lab Activity Task
      • SHELL Lab Activity Solution
  • ASSIGNMENTS
    • Assignment-1 SHELL Solutions
Powered by GitBook
On this page

Was this helpful?

  1. Web Technologies

JavaScript

This section contains some basic usage of JavaScript along with some examples.

JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more. JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, Opera. Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called the JavaScript engine.

  • JavaScript was designed to add interactivity to HTML pages

  • JavaScript is a scripting language (a scripting language is a lightweight programming language)

  • A JavaScript consists of lines of executable computer code

  • A JavaScript is usually embedded directly into HTML pages

  • JavaScript is an interpreted language (means that scripts execute without preliminary compilation)

  • Everyone can use JavaScript without purchasing a license

Are Java and JavaScript the Same? - NO! Java and JavaScript are two completely different languages in both concept and design! Java (developed by Sun Microsystems) is a powerful and much more complex programming language -in the same category as C and C++.

Sample JavaScript

<html>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>

JavaScript Engine

  • The browser has an embedded engine sometimes called a “JavaScript virtual machine”.

  • Different engines have different “codenames”. For example:

    • V8 –in Chrome and Opera.

    • Spider Monkey –in Firefox.

  • There are other codenames like “Trident” and “Chakra” for different versions of IE, “ChakraCore” for Microsoft Edge, “Nitro” and “SquirrelFish” for Safari, etc.

  • The terms above are good to remember because they are used in developer articles on the internet. We’ll use them too. For instance, if “a feature X is supported by V8”, then it probably works in Chrome and Opera

Ending Statements With a Semicolon?

  • With traditional programming languages, like C++ and Java, each code statement has to end with a semicolon (;).

  • Many programmers continue this habit when writing JavaScript, but in general, semicolons are optional!

  • However, semicolons are required if you want to put more than one statement on a single line.

JavaScript Variables

  • Variables are used to store data.

  • A variable is a "container" for the information you want to store.

  • A variable's value can change during the script.

  • You can refer to a variable by name to see its value or to change its value.

  • Rules for variable names:

    • Variable names are case sensitive

    • They must begin with a letter or the underscore character •

      • strname –STRNAME (not same)

Arithmetic Operations

Assignment Operations

Comparison Operators

Logical Operations

JavaScript Pop-Up Boxes

Alert Box - An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed.

<script>alert("Hello World!")</script>

Confirm Box - A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.

<html>
<head> 
<title>JS Confirm Box</title>
</head>
<body>
<p>Click to display a confirm box.</p>
<button onclick="myFunction()">Click Here</button>
<script>
function myFunction() 
{
confirm("Press the button!");
}
</script>
</body>
</html>

Prompt Box - A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK“, the box returns the input value. If the user clicks "Cancel“, the box returns null.

<script>
x=prompt("Is this a Prompt Box  :", " ")
document.write("This is a Prompt Box :"+x)
</script>

Conditional Statements - Example for If and Else

<script>
x=3
if(x<0)
{
alert (“Negative”)
}
else
{
alert (“Positive”)
}
</script>

Additional Resources:

PreviousCSSNextDatabase Systems

Last updated 3 years ago

Was this helpful?

Mozilla Resources -

All about JavaScript -

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
https://javascript.info/