Introduction To JavaScript-All
Introduction To JavaScript-All
Separation of Concerns
Presentation
Styles the Tags
Functional
Modify the Tags
Fundamentals of Web Programming 2
JavaScript - Introduction
• JavaScript is the programming language of the Web.
• JavaScript is a Client-Side Scripting Language
• It tells the browser to go do the work
• All modern HTML pages are using JavaScript.
• It is the language for HTML, for the Web, for computers,
servers, laptops, tablets, smart phones, and more.
• JavaScript Makes Webpages more interactive
• JavaScript is not the same as Java
• But has various similarities with the programming language
• JavaScript is case sensitive
CONFIRM
PROMPT
prompt("What is XML?", ":(");
Returns a value also
Types of Variables
• Numbers: Integers, Decimal Numbers, Negative Numbers
• Text / String: “Use quotations for values”
• Boolean: true / false
• No Value: null (Empty Variable) – Not same as a zero
Fundamentals of Web Programming 23
Example
Quotes
• You can use both ‘single quotes’ and “double quotes”
var str = “This is a sample string”;
var str = ‘This is a sample string’;
• You can use quotes inside a string, as long as they don't match the quotes surrounding
the string
var answer1 = "It's alright";
var answer2 = "He is called 'Johnny'";
Concatenation
Use the “+” operator to join two strings
var x=“Web”;
var y= “Systems”;
document.write(x + “ “+y); Fundamentals of Web Programming 25
Comments
• A single-line comment begins with the characters // and terminates at
the end of the line
• Comments do not cause the browser to perform any action when the
script is interpreted; rather, comments are ignored by the JavaScript
interpreter
• Multiline comments begin with delimiter /* and end with delimiter */
All text between the delimiters of the comment is ignored by the interpreter.
if(a===b) //false
SYNTAX
do while (condition)
{ {
more JavaScript commands more JavaScript commands
update inside update inside
} while (condition); }
Fundamentals of Web Programming 35
Example 2
<script type=“text/javascript”>
//Code goes here Internal
</script>
<script type=“text/javascript”>
alert(‘Welcome’);
</script>
<script type=“text/javascript”>
In the Body
</script> Functions that needs running after the
</body> whole page (body) of the HTML is loaded
</html> Fundamentals of Web Programming 43
JavaScript Location – External
script.js
function test()
{
alert(‘Hello’);
}
Inside the head
or the body tag
<html>
<head>
<script src=“script.js”></script>
</head>
<body>
</body>
</html>