Momina Mustehsan Best Photos 2016 | Coke Studio Girl “Momina Mustehsan”
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad
description
Transcript of CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad
![Page 1: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/1.jpg)
CSC 330 E-CommerceCSC 330 E-CommerceTeacher
Ahmed Mumtaz MustehsanAhmed Mumtaz Mustehsan GM-IT CIIT IslamabadGM-IT CIIT Islamabad
Virtual Campus, CIITCIITCOMSATS Institute of Information Technology
T2-Lecture-6xT2-Lecture-6x
![Page 2: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/2.jpg)
JavaScriptJavaScript
Part - IPart - I
For Lecture Material/Slides Thanks to: www.w3schools.com
![Page 3: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/3.jpg)
SynopsisSynopsis
IntroductionJavaScript Where ToJavaScript OutputJavaScript SyntaxJavaScript StatementsJavaScript CommentsJavaScript VariablesJavaScript Data Type
3 T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com
![Page 4: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/4.jpg)
IntroductionIntroduction
![Page 5: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/5.jpg)
IntroductionIntroductionJavaScript is the programming language of the Web.All modern HTML pages are using JavaScript.JavaScript is one of 3 languages that all web
developers MUST learn:HTML to define the content of web pagesCSS to specify the layout of web pagesJavaScript to program the behavior of web pagesJavaScript is the most popular programming
language in the world. It is the language for HTML, for the Web, for
computers, servers, laptops, tablets and smart phones.
5 T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com
![Page 6: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/6.jpg)
Where To place JavaScript Where To place JavaScript
In HTML, Java Scripts must be inserted between <script> and </script> tags.
The lines between <script> and </script> contain the JavaScript code:
Java Scripts can be put in the <body> and in the <head> section of an HTML page.
6 T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com
![Page 7: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/7.jpg)
ExampleExample
<script>function myFunction() { document.getElementById("demo").innerHTML = "My First JavaScript Function";}
</script>
Just take it for a fact, that the browser will interpret the code between the <script> and </script> tags as JavaScript.
Old examples may have type="text/javascript" in the <script> tag. This is no longer required.
JavaScript is the default scripting language in all modern browsers and in HTML5.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com 1-7
![Page 8: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/8.jpg)
JavaScript Functions and EventsJavaScript Functions and Events
Often, JavaScript code is written to be executed when an event occurs, like when the user clicks a button.
JavaScript code inside a function, can be invoked later, when an event occurs.
Invoke a function = Call upon a function (ask for the code in the function to be executed).
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com 1-8
![Page 9: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/9.jpg)
JavaScript in <head> or <body>JavaScript in <head> or <body>
You can place any number of scripts in an HTML document.
Scripts can be placed in the <body> or in the <head> section of HTML, and/or in both.
Scripts may also be placed at the bottom of the <body> section of a web page. This can reduce display time.
Sometimes you will see all JavaScript functions in the <head> section.
Separating HTML and JavaScript, by putting all the code in one place, is always a good habit.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com 1-9
![Page 10: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/10.jpg)
JavaScript in <head>JavaScript in <head>
In this example, a JavaScript function is placed in the <head> section of an HTML page.The function is invoked (called) when a button is clicked:
<!DOCTYPE html><html><head><script>function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed.“;}</script></head>
<body>
<h1>My Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
</body></html>
Demo!!!
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-10
![Page 11: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/11.jpg)
JavaScript in <body>JavaScript in <body>
In this example, a JavaScript function is placed in the <body> section of an HTML page.
The function is invoked (called) when a button is clicked:
<!DOCTYPE html><html><body><h1>My Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
<script>function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed.";}</script>
</body></html>
◦Demo2!!!
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-11
![Page 12: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/12.jpg)
External JavaScriptsExternal JavaScripts
Scripts can also be placed in external files.External scripts are practical when the same code is
used in many different web pages.External JavaScript files have the file extension .js.To use an external script, put the name of the script
file in the source (src) attribute of the <script> tag:◦ <!DOCTYPE html>
<html><body><script src="myScript.js"></script></body></html>
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-12
![Page 13: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/13.jpg)
External JavaScripts…External JavaScripts…
You can place an external script reference in <head> or <body> as you like.
The script will behave as if it was located exactly where you put the reference in the HTML document.
External scripts cannot contain <script> tags.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-13
![Page 14: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/14.jpg)
JavaScript OutputJavaScript Output
![Page 15: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/15.jpg)
JavaScript OutputJavaScript Output
JavaScript does not have any print or output functions.
In HTML, JavaScript can only be used to manipulate HTML elements.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-15
![Page 16: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/16.jpg)
Manipulating HTML ElementsManipulating HTML Elements To access an HTML element from JavaScript, you can use the
document.getElementById(id) method. Use the "id" attribute to identify the HTML element, and innerHTML to
refer to the element content:
<!DOCTYPE html><html><body>
<h1>My First Web Page</h1>
<p id="demo">My First Paragraph</p>
<script>document.getElementById("demo").innerHTML = "Paragraph changed.";</script>
</body></html>
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-16
![Page 17: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/17.jpg)
Manipulating HTML Elements…Manipulating HTML Elements…
The JavaScript statement (inside the <script> tag) is executed by the web browser:
document.getElementById("demo") is JavaScript code for finding an HTML element using the id attribute.
innerHTML = "Paragraph changed." is JavaScript code for changing an element's HTML content (innerHTML).
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-17
![Page 18: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/18.jpg)
Writing to The HTML DocumentWriting to The HTML Document
For testing purposes, you can use JavaScript to write directly to the HTML document:◦ <!DOCTYPE html>
<html><body><h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>document.write(Date());</script></body></html>
◦ Demo-write!!
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-18
![Page 19: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/19.jpg)
Writing to The HTML Document…Writing to The HTML Document… Use document.write for testing only. If you execute it, on a loaded HTML document, all HTML elements will
be overwritten.
◦ <!DOCTYPE html><html><body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<button onclick="myFunction()">Try it</button>
<script>function myFunction() { document.write(Date());}</script>
</body></html>
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-19
![Page 20: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/20.jpg)
Writing to The ConsoleWriting to The Console If your browser supports debugging, you can use
the console.log() method to display JavaScript values in the browser. Activate debugging in your browser with F12, and select "Console" in
the debugger menu.
<!DOCTYPE html><html><body>
<h1>My First Web Page</h1>
<script>a = 5;b = 6;c = a + b;console.log(c);</script>
</body></html>
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-20
![Page 21: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/21.jpg)
Writing to The ConsoleWriting to The Console
Debugging is the process of testing, finding, and reducing bugs (errors) in computer programs.
The first known computer bug was a real bug (an insect), stuck in the electronics.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-21
![Page 22: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/22.jpg)
JavaScript SyntaxJavaScript Syntax
![Page 23: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/23.jpg)
JavaScript SyntaxJavaScript Syntax
JavaScript is a programming language. The Syntax rules define how the language is constructed.
JavaScript is a scripting language. It is a lightweight, but powerful, programming language.
Syntax :Syntax : "The principles by which sentences are constructed in a language."
The sentences of a programming language are called computer statements, or just statements.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-23
![Page 24: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/24.jpg)
JavaScript LiteralsJavaScript Literals
In a programming language, literals are constant values like 3.14.
Number literals can be written with or without decimals, and with or without scientific notation (e):◦ 3.14
1001
123e5
String literals can be written with double or single quotes:◦ "John Doe"
'John Doe'
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-24
![Page 25: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/25.jpg)
JavaScript VariablesJavaScript Variables
In a programming language, variables are containers for storing information (data).
The equal sign (=) assigns a value to a named variable (just like in normal algebra):
x = 5
length = 6
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-25
![Page 26: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/26.jpg)
JavaScript OperatorsJavaScript Operators
JavaScript uses operators to compute values (just like algebra):
5 + 6
a * b JavaScript can assign computed values to named
variables (just like algebra): x = 5 + 6
y = x * 10Expressions like 5 + 6, and x * 10, are called expression
literals.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-26
![Page 27: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/27.jpg)
JavaScript StatementsJavaScript Statements
In HTML, JavaScript statements are written as sequences of "commands" to the HTML browser.
Statements are separated by semicolons: x = 5 + 6;
y = x * 10;
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-27
![Page 28: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/28.jpg)
JavaScript KeywordsJavaScript Keywords
A JavaScript statement often starts with a keyword. The var keyword tells the browser to create a new variable:
var x = 5 + 6;var y = x * 10;
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-28
![Page 29: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/29.jpg)
JavaScript CommentsJavaScript Comments
Not all JavaScript statements are "commands". Anything after double slashes // is ignored by the browser: considered as comments for self documentation.
// I will not be executed
Comments will be discussed later!
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-29
![Page 30: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/30.jpg)
JavaScript Data TypesJavaScript Data TypesJavaScript variables can hold many types of data:
numbers, text strings, arrays, objects and much more:
var length = 16; // Number assigned by a number literal var lastName = "Johnson"; // String assigned by a string literalvar cars = [“Toyota", “Honda", "BMW"]; // Array assigned by an array literal
// Object assigned by an object literal
var person = {firstName:John, lastName:Doe};
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-30
![Page 31: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/31.jpg)
JavaScript FunctionsJavaScript Functions
JavaScript statements written inside a function, can be invoked many times (reused):
Invoke a function = Call upon a function (ask for the code in the function to be executed).
function myFunction(a, b) { return a * b; // returns the product of a and b}
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-31
![Page 32: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/32.jpg)
JavaScript IdentifiersJavaScript Identifiers
All programming languages must identify variables, functions, and objects, with unique names.
These unique names are called identifiers. Identifier names can contain letters, digits,
underscores, and dollar signs, but cannot begin with a number.
Reserved words (like JavaScript keywords) cannot be used as identifiers.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-32
![Page 33: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/33.jpg)
JavaScript is Case SensitiveJavaScript is Case Sensitive
In JavaScript all identifiers are case sensitive. The variables lastName and lastname, are two
different variables.The functions myFunction and myfunction, are two
different functions.JavaScript does not interpret Var; as var.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-33
![Page 34: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/34.jpg)
JavaScript Character SetJavaScript Character Set
JavaScript uses the Unicode character set.Unicode covers (almost) all the characters,
punctuations, and symbols in the world.
It is common, in JavaScript, to use camelCase names.You will often see identifier names written like lastName (instead of lastname).
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-34
![Page 35: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/35.jpg)
JavaScript StatementsJavaScript Statements
![Page 36: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/36.jpg)
JavaScript StatementsJavaScript Statements
In HTML, JavaScript statements are "commands" to the browser.
The purpose, of the statements, is to tell the browser what to do.
This JavaScript statement tells the browser to write " WelCome to Java Script " inside an HTML element identified with id="demo":
Example document.getElementById("demo").innerHTML =
“WelCome to Java Script.";
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-36
![Page 37: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/37.jpg)
Semicolon ;Semicolon ;Semicolon separates JavaScript statements.Normally you add a semicolon at the end of each
executable statement.Using semicolons also makes it possible to write
many statements on one line.Writing:a = 5;b = 6;c = a + b;Is the same as writing:
a = 5; b = 6; c = a + b;
You might see examples without semicolons. Ending statements with semicolon is optional in JavaScript.
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-37
![Page 38: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/38.jpg)
JavaScript CodeJavaScript Code
JavaScript code (or just JavaScript) is a sequence of JavaScript statements.
Each statement is executed by the browser in the sequence they are written.
This example will manipulate two different HTML elements:
Example document.getElementById("demo").innerHT
ML = " WelCome to Java Script.";document.getElementById("myDiv").innerHTML = "How are you?";
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-38
![Page 39: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/39.jpg)
JavaScript Code BlocksJavaScript Code Blocks JavaScript statements can be grouped together in blocks. Blocks start with a left curly bracket, and end with a right curly
bracket. The purpose of a block is to make the sequence of statements
execute together. A good example of statements grouped together in blocks, are
in JavaScript functions. This example will run a function that will manipulate two HTML
elements: Example function myFunction() {
document.getElementById("demo").innerHTML = “Welcome to Java Script."; document.getElementById("myDIV").innerHTML = "How are you?";}
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-39
![Page 40: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/40.jpg)
JavaScript Statement IdentifiersJavaScript Statement Identifiers
JavaScript statements often start with a statement identifier to identify the JavaScript action to be performed.
Statement identifiers are reserved words and cannot be used as variable names (or any other things).
Here is a list of some of the JavaScript statements (reserved words)
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-40
![Page 41: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/41.jpg)
JavaScript Statement Identifiers…JavaScript Statement Identifiers… Here is a list of some of the JavaScript statements (reserved words)
you will learn about in this tutorial:
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-41
![Page 42: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/42.jpg)
JavaScript White Space in JavaScript JavaScript White Space in JavaScript StatementsStatementsJavaScript ignores extra spaces. You can add white
space to your script to make it more readable.The following lines are equivalent:
◦ var person="Hege"var person = "Hege"
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-42
![Page 43: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/43.jpg)
Breaking a JavaScript StatementBreaking a JavaScript Statement
You can break up a code line within a text string with a backslash:◦ var text = "Hello \
World!";However, you cannot break up a code line like this:
◦ var text = \ "Hello World!";
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com1-43
![Page 44: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/44.jpg)
JS CommentsJS Comments
![Page 45: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/45.jpg)
JavaScript CommentsJavaScript Comments
JavaScript comments can be used to explain the code, and make the code more readable.
JavaScript comments can also be used to prevent execution, when testing alternative code.
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-45
![Page 46: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/46.jpg)
Single Line CommentsSingle Line Comments
Single line comments start with //.Any text between // and the end of a line, will be
ignored by JavaScript (will not be executed).The following example uses a single line comment in
front of each line, to explain the code:
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-46
![Page 47: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/47.jpg)
ExampleExample
// Change heading:document.getElementById("myH").innerHTML = "My First Page";// Change paragraph:document.getElementById("myP").innerHTML = "My first paragraph.";
This example uses a single line comment at the end of each line, to explain the code:
var x = 5; // Declare x, give it the value of 5var y = x + 2; // Declare y, give it the value of x + 2
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-47
![Page 48: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/48.jpg)
Multi-line CommentsMulti-line Comments
Multi-line comments start with /* and end with */.Any text between /* and */ will be ignored by
JavaScript.The following example uses a multi-line comment (a
comment block) to explain the code:
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-48
![Page 49: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/49.jpg)
Using Comments to Prevent ExecutionUsing Comments to Prevent Execution
Using comments to prevent execution of code, can be very suitable for testing.
Adding // in front of a code line changes the code lines from an executable line to a comment.
The next example uses // to prevent execution of one of the code lines.
//document.getElementById("myH").innerHTML = "My First Page";document.getElementById("myP").innerHTML = "My first paragraph.";
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-49
![Page 50: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/50.jpg)
ExampleExample
/*The code below will changethe heading with id = "myH"and the paragraph with id = "myp"in my web page:*/document.getElementById("myH").innerHTML = "My First Page";document.getElementById("myP").innerHTML = "My first paragraph.";
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-50
![Page 51: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/51.jpg)
Example Example
The following example uses a comment block to prevent execution of multiple lines:
/*document.getElementById("myH").innerHTML = "My First Page";document.getElementById("myP").innerHTML = "My first paragraph.";*/
T2-Lecture-7 Ahmed Mumtaz Mustehsan www.w3schools.com1-51
![Page 52: CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad](https://reader034.fdocuments.net/reader034/viewer/2022051316/56813b6d550346895da4726d/html5/thumbnails/52.jpg)
The End JavaScript The End JavaScript Part-IPart-I
Thank YouThank You
T2-Lecture-6 Ahmed Mumtaz Mustehsan www.w3schools.com
1-52