Lec 5 - SET 372 - JS - Introduction
Lec 5 - SET 372 - JS - Introduction
Internet Application
05 Development
For example, you might use JavaScript to check if the user has
entered a valid e-mail address in a form field.
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 drag-and-drop
components and sliders to give a Rich Interface to your site visitors.
HTML
Client-side JavaScript code is embedded within HTML
documents in Four ways:
19-Mar-
Web Programming 24
The <script> Element in 15
<body>...</ body > Section
This case when you need a script to run as the page loads
In this case, you would not have any function defined using JavaScript.
JavaScript functions that are registered with the web browser and
then invoked by the web browser in response to events (such as
user input).
Example keyword, must be typed "while" not " While" or " WHILE”
online, Online, OnLine, and ONLINE are four distinct variable names.
var i, sum; And you can combine variable declaration with variable
initialization: var message = "hello"; var i = 0, j = 0, k = 0; If you don't
specify an initial value for a variable with the var statement, the variable
is declared, but its value is undefined until your code stores a value into
it.
JavaScript does not make a distinction between integer values and floating-point
values.
Sometimes, your code will include strings which are very long.
You can use the + operator to append multiple strings together, like this:
var longString = "This is a very long string which needs " + "to wrap
across multiple lines because " + "otherwise my code is unreadable.";
Or you can use the backslash character (“ \”) at the end of each line to
indicate that the string will continue on the next line.
var longString = "This is a very long string which needs \ to wrap across
multiple lines because \ otherwise my code is unreadable”;
text =
We are the so-called
i.e.
let text = "We are the so-called \"Vikings\" from the north.";
text =
We are the so-called "Vikings" from the north.
Boolean is a logical data type that can have only the values true or
false.
JavaScript Booleans can have one of two values: true or false.
var completed = false;
If (isMember)
discount = 15;
element = document.getElementById("i1");
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Global Properties </h1>
<h2>The undefined Property </h2>
<p id="demo"> </p>
<script>
JavaScript Global Properties
let x; The undefined Property
if (x === undefined) { x is undefined
text = "x is undefined"; }
else { text = "x is defined"; }
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html> 19-Mar-
24
Difference between null and 35
undefined
typeof null // “object” (not “null" for legacy reasons)
!null //true