JavaScript
JavaScript
By
Dr
Yasser Ali
44208213
JavaScript is a high-level programming language that follows
the ECMAScript standard. It was originally designed as a scripting
language for websites but became widely adopted as a general-purpose
programming language, and is currently the most popular programming
language in use.[1] JavaScript is usually found running in a web browser as
interactive or automated content, ranging from popup messages and
live clocks to large web applications. JavaScript is also commonly used
in server-side programming through platforms like Node.js, or "embedded" in
non-JavaScript applications where the base programming language lacks the
high-level functionality that JavaScript offers.
JavaScript is typically inserted into HTML when used on the web, either
directly in the file in an HTML tag, or linked to a separate file containing the
script.
JavaScript, as a full featured scripting language, can be used to provide
functionality to a website. Examples include:
Video Games
JavaScript can be used to create and run video games in the browser. The
modern web has quickly become a viable platform for creating and
distributing high-quality games. With modern web technologies and a recent
browser, it’s entirely possible to make stunning, top-notch games for the web.
JavaScript is blazing fast in modern browsers and getting faster all the time.
You can use its power to write the code for your game or look at using
technologies like Emscripten or Asm.js to easily port your existing games.
There are also many widely adopted game engines that you can use to
develop games with JavaScript and HTML5. Some popular ones include
Three.js, Pixi.js, Phaser, Babylon.js, Matter.js, and PlayCanvas. These game
engines provide a range of features and tools to help you create
sophisticated 2D and 3D graphics without relying on third-party plugins.[4]
// ES5
var x = 1;
// ES6+
const y = 10; // Cannot be reassigned
let t = 5; // Can be reassigned
Examples
[change | change source]
The script below prints "Example" on the screen. The lines that start
with // are comments, which are used to describe the actions of the
program.[8]
function sayHi() {
let name = prompt("What's your name?");
// This name is saved to a variable
/*
This is also a comment,
but it can span multiple lines.
*/
<!DOCTYPE html>
<head>
<title>Example page</title>
<script> // This is the script tag
/*
This puts the number, then a new line element
(<br>),
at the end of the web page.
*/
// End javascript:
</script>
</head>
<body></body>
The for() loop makes whatever code is between the { and the } happen
more than one time. In this case, it keeps looping
until numOfTimesAround is equal to 10, then it stops. This means it equals
ten. It's a bit confusing at first, but it works.
Differences between Java and Javascript
In Java, to define a variable, you have to say what type of variable it is: a
number, a word, a letter, or more. In JavaScript, this is not necessary.
In JavaScript, functions are stored as variables (unlike Java). This makes
the following code okay in JavaScript:
function sayHi() {
alert("Hi!");
}
sayBye = function() {
alert("Bye!");
}
sayHi();
sayBye();