Java script
Java script
2
Web Concepts
06. JavaScript 1/2 Mohammed
AbuJarour
05.11.24
* SUBJECT TO CHANGE
Plan
Today!
5
JavaScript – history
Version Official Name
• JavaScript was invented by Brendan Eich from 1 ECMAScript 1 (1997)
Netscape (web browser) in 1995 2 ECMAScript 2 (1998)
Client-side Server-side
• Browser support • Promoted by Gmail and Google
• User setting Maps (client-side)
• Nodejs
6. React to user actions, run on mouse clicks, pointer movements, key presses.
7. Send requests over the network to remote servers, download and upload files
8. Get and set cookies, ask questions to the visitor, show messages
<head> <head>
<title>JavaScript 101</title> <title>JavaScript 101</title>
<script> <script src="js-sample-01.js"></script>
function greet() {
/* ... */
}
</script>
</head> </head>
</html> </html>
<head>
one.html <title>Page Title</title>
<link rel="stylesheet" type="text/css" href="one.css">
<script src="one.js"></script>
</head>
<body onload="greet();">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p id="greeting"></p>
</body>
</html
one.css
body {
background-color: lightblue;
one.js
} function greet() {
var time = new Date();
h1 { var hours = time.getHours();
color: white; var greeting = "Good morning!";
} if (hours >= 12 && hours < 18)
greeting = "Good afternoon!";
p{ else if (hours >= 18 && hours <= 23)
font-size: 20px; greeting = "Good evening!";
}
document.getElementById("greeting").innerHTML = greeting;
}
<head> <head>
<title>JavaScript 101</title> <title>JavaScript 101</title>
<script> </head>
function greet() {
/* ... */ <body onload="greet();">
} <!-- ... -->
</script> <script>
</head> function greet() {
/* ... */
<body onload="greet();"> }
<!-- ... --> </script>
</body> </body>
</html> </html>
document.getElementById("greeting").innerHTML = greeting;
}
Event
Event Description
onmouseout The user moves the mouse away from an HTML element
var f = document.getElementById('f').value;
var c = toCelsius(f);
/ Division
++ Increment
-- Decrement
• JavaScript has dynamic types → The same variable can be used to hold different
data types
• Strings are written with quotes. You can use single or double quotes.
• Numbers can be written with or without decimals
• Booleans can only have two values: true or false.
• In JavaScript, a variable without a value, has the value undefined. The type is
also undefined.
• Any variable can be emptied, by setting the value to undefined. The type will also
be undefined.
var a = "100";
var b = "10";
var c = a / b; // c will be 10
var d = a * b; // d will be 1000
var e = a - b; // e will be 90
var f = a + b; // f will not be 110 (It will be 10010)
var a = "100";
var b = "10";
var c = a / b; // c will be 10
var d = a * b; // d will be 1000
var e = a - b; // e will be 90
var f = a + b; // f will not be 110 (It will be 10010)
var g = Number(a) + Number(b); // g will be 110
• NaN is a JavaScript reserved word indicating that a value is not a legal number
• isNaN() is a global JavaScript function that checks whether a value is not a legal
number
• Infinity (or -Infinity) is the value JavaScript will return if you calculate a number
getHours() Get the hour (0-23) setHours() Set the hour (0-23)
getMinutes() Get the minute (0-59) Set the milliseconds (0-999)
setMilliseconds()
getSeconds() Get the second (0-59)
setMinutes() Set the minutes (0-59)
getMilliseconds() Get the millisecond (0-999)
setMonth() Set the month (0-11)
getTime() Get the time (milliseconds since
January 1, 1970) setSeconds() Set the seconds (0-59)
getDay() Get the weekday as a number (0-6) setTime() Set the time (milliseconds since
Get the time. ECMAScript 5. January 1, 1970)
Date.now()
atan2(y, x) Returns the arctangent of the quotient of its random() Returns a random number between 0 and 1
arguments round(x) Rounds x to the nearest integer
atanh(x) Returns the hyperbolic arctangent of x Returns the sine of x (x is in radians)
sin(x)
cbrt(x) Returns the cubic root of x
sinh(x) Returns the hyperbolic sine of x
ceil(x) Returns x, rounded upwards to the nearest
integer sqrt(x) Returns the square root of x
cos(x) Returns the cosine of x (x is in radians) tan(x) Returns the tangent of an angle
cosh(x) Returns the hyperbolic cosine of x tanh(x) Returns the hyperbolic tangent of a number
x
exp(x) Returns the value of E trunc(x) Returns the integer part of a number (x)
The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
• https://www.w3schools.com/js/default.asp
• https://javascript.info/
• https://www.valentinog.com/blog/event/
• Professional JavaScript for Web Developers –Nicholas C. Zakas