JavaScript
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,[2] or "embedded" in non-JavaScript applications where the base programming language lacks the high-level functionality that JavaScript offers. Despite the similarities in name and syntax, JavaScript is not related to the programming language Java. Though the names of both languages are trademarks of Oracle Corporation, the two languages follow different design principles, and are actively developed by unrelated organizations. Object Model window (Global Object) │ ├── BOM (Browser Object Model) │ ├── location │ │ ├── href │ │ ├── hostname │ │ ├── pathname │ │ ├── protocol │ │ ├── assign() │ │ ├── reload() │ │ └── replace() │ │ │ ├── navigator │ │ ├── userAgent │ │ ├── language │ │ ├── platform │ │ └── geolocation │ │ │ ├── history │ │ ├── length │ │ ├── back() │ │ ├── forward() │ │ └── go() │ │ │ ├── screen │ │ ├── width │ │ ├── height │ │ ├── availWidth │ │ └── availHeight │ │ │ ├── console │ │ ├── log() │ │ ├── error() │ │ ├── warn() │ │ └── info() │ │ │ ├── alert() │ ├── prompt() │ ├── confirm() │ ├── open() │ └── close() │ ├── DOM (Document Object Model) │ ├── document │ │ ├── documentElement (<html>) ← Root of DOM │ │ │ ├── head (<head>) │ │ │ │ ├── title (<title>) │ │ │ │ ├── meta (<meta>) │ │ │ │ ├── link (<link>) │ │ │ │ ├── style (<style>) │ │ │ │ ├── script (<script>) │ │ │ │ ├── noscript (<noscript>) │ │ │ │ └── template (<template>) │ │ │ │ │ │ │ └── body (<body>) │ │ │ ├── header (<header>) │ │ │ ├── nav (<nav>) │ │ │ ├── main (<main>) │ │ │ ├── section (<section>) │ │ │ ├── article (<article>) │ │ │ ├── aside (<aside>) │ │ │ ├── footer (<footer>) │ │ │ └── div (<div>) │ │ │ ├── p (<p>) │ │ │ ├── span (<span>) │ │ │ ├── a (<a>) │ │ │ ├── img (<img>) │ │ │ ├── ul (<ul>) │ │ │ │ └── li (<li>) │ │ │ ├── ol (<ol>) │ │ │ │ └── li (<li>) │ │ │ ├── table (<table>) │ │ │ │ ├── thead (<thread>) │ │ │ │ │ └── tr (<tr>) │ │ │ │ │ ├── th (<th>) │ │ │ │ │ └── td (<td>) │ │ │ │ ├── tbody (<tbody>) │ │ │ │ │ └── tr (<tr>) │ │ │ │ │ ├── th (<th>) │ │ │ │ │ └── td (<td>) │ │ │ │ └── tfoot (<tfoot>) │ │ │ ├── form (<form>) │ │ │ │ ├── input (<input>) │ │ │ │ ├── textarea (<textarea>) │ │ │ │ ├── select (<select>) │ │ │ │ │ └── option (<option>) │ │ │ │ └── button (<button>) │ │ │ ├── script (<script>) │ │ │ ├── iframe (<iframe>) │ │ │ ├── video (<video>) │ │ │ │ └── source (<source>) │ │ │ ├── audio (<audio>) │ │ │ │ └── source (<source>) │ │ │ ├── canvas (<canvas>) │ │ │ └── svg (<svg>) │ │ │ │ │ ├── location (document.location.href) │ │ ├── getElementById() │ │ ├── getElementsByClassName() │ │ ├── querySelector() │ │ ├── querySelectorAll() │ │ ├── createElement() │ │ ├── appendChild() │ │ ├── removeChild() │ │ ├── replaceChild() │ │ └── cloneNode() │ │ │ ├── Nodes │ │ ├── Element Nodes (<div>, <p>, <img>, etc.) │ │ ├── Text Nodes (Text inside elements) │ │ ├── Comment Nodes () │ │ └── Attribute Nodes (Element attributes) │ │ │ ├── Events │ │ ├── click │ │ ├── keydown │ │ ├── mousemove │ │ ├── load │ │ ├── focus │ │ ├── blur │ │ ├── submit │ │ └── change │ │ │ ├── Storage │ │ ├── localStorage │ │ ├── sessionStorage │ │ └── cookies (document.cookie) │ │ │ ├── Shadow DOM │ │ ├── attachShadow() │ │ └── shadowRoot │ │ │ ├── Custom Elements │ │ ├── define() │ │ └── observedAttributes │ │ │ └── Web APIs │ ├── fetch() │ ├── XMLHttpRequest │ ├── WebSockets │ ├── IndexedDB │ ├── Service Workers │ └── WebRTC │ └── CSSOM (CSS Object Model) ├── document.styleSheets ← List of all stylesheets │ └── CSSStyleSheet ← Represents a single stylesheet │ ├── cssRules / rules ← All CSS rules inside a stylesheet │ │ ├── CSSRule │ │ ├── CSSStyleRule │ │ ├── CSSMediaRule (@media queries) │ │ ├── CSSImportRule (@import) │ │ ├── CSSFontFaceRule (@font-face) │ │ ├── CSSSupportsRule (@supports) │ │ ├── CSSNamespaceRule (@namespace) │ │ ├── CSSPageRule (@page) │ │ ├── CSSKeyframesRule (@keyframes) │ │ ├── CSSKeyframeRule (Individual keyframe inside @keyframes) │ │ ├── CSSCounterStyleRule (@counter-style) │ │ └── CSSPropertyRule (@property) │ ├── insertRule("rule", index) │ └── deleteRule(index) │ ├── getComputedStyle(element) │ ├── getPropertyValue('property') │ ├── color │ ├── font-size │ ├── background-color │ ├── display │ ├── position │ ├── z-index │ ├── opacity │ ├── transform │ ├── transition │ ├── animation │ └── visibility │ ├── element.style │ ├── setProperty('property', 'value') │ ├── removeProperty('property') │ ├── color │ ├── fontSize │ ├── backgroundColor │ ├── display │ ├── position │ ├── transform │ ├── transition │ ├── animation │ └── visibility │ ├── CSSStyleDeclaration ← Represents all styles of an element │ ├── length │ ├── item(index) │ ├── getPropertyValue('property') │ ├── setProperty('property', 'value', 'priority') │ └── removeProperty('property') │ └── CSS Variables (Custom Properties) ├── document.documentElement.style.setProperty('--var', 'value') ├── element.style.getPropertyValue('--var') ├── element.style.removeProperty('--var') └── getComputedStyle(element).getPropertyValue('--var') UseJavaScript 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:
FrameworksA majority of websites use what is known as a framework. Frameworks may allow programming to be easier as more predefined procedures are defined within it. Such a library is jQuery. Video GamesJavaScript 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.[3] 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] Beyond web browsersJavaScript is also used outside of web browsers. As a scripting language, JavaScript can be used to define the behaviour of applications such as extensions in GNOME Shell. In addition, there are runtime environments for running JavaScript as a server side programming language. Such an environment is Node.js. Electron is a framework which allows graphical applications to be made with web technologies, by running on the Chromium browser and Node.js. SyntaxA JavaScript program is made of a collection of instructions called "statements". A semicolon marks the end of a statement, and allows multiple statements to be placed on the same line. However, it is typical to write each statement on its own line to keep a program file readable. Variables can be defined in several ways. In an older version named "ES5", variables are defined using the var keyword.[5] In the newer versions after ES5, variables can be defined using const for constant variables and let for local variables.[6][7] The value of constant variables cannot be re-declared or reassigned. Variables assigned using const or let are contained within blocks, while variables assigned using var are contained within functions. // ES5
var x = 1;
// ES6+
const y = 10; // Cannot be reassigned
let t = 5; // Can be reassigned
ExamplesThe script below prints "Example" on the screen. The lines that start with function sayHi() {
let name = prompt("What's your name?");
// This name is saved to a variable
alert("Hello " + name);
// Whatever the name is, the browser alerts "Hello (name)"
}
sayHi(); // Runs the function sayHi
/*
This is also a comment,
but it can span multiple lines.
*/
The code above alerts If you want to put JavaScript in your HTML, you put it between an opening <!DOCTYPE html>
<head>
<title>Example page</title>
<script> // This is the script tag
for (let counter = 1; counter <= 10; counter++) {
document.body.innerHTML = document.body.innerHTML + counter + "<br>";
/*
This puts the number, then a new line element (<br>),
at the end of the web page.
*/
}
// End javascript:
</script>
</head>
<body></body>
The Differences between Java and Javascript
function sayHi() {
alert("Hi!");
}
sayBye = function() {
alert("Bye!");
}
sayHi();
sayBye();
Related pagesReferences
Other websites
|
Portal di Ensiklopedia Dunia