Open original
Info
Demo 2.3

JavaScript is for functionality

Files in this demo

├─ index.html
├─ style.css
└─ script.js

HTML gives a page content and CSS makes it look good — but so far the page just sits there. JavaScript makes a page do things in response to the visitor.

JavaScript can listen for events (like a click), remember information in variables, and change the page while it’s running. Here, clicking the button runs a small function that adds one to a counter and updates the text below it.

JavaScript goes inside a <script> element. Click the button in the preview to try it!

Next demoJavaScript libraries make your life easier
Keyboard Shortcuts
⌘ Z / ⌘ ⇧ ZCtrl Z / Ctrl ⇧ Z Undo / redo
Tab / ⇧ TabTab / ⇧ Tab Indent / unindent selection
⌘ ] / ⌘ [Ctrl ] / Ctrl [ Indent / unindent lines
⌘ ACtrl A Select all
⌘ DCtrl D Select next occurrence of selection
⌘ /Ctrl / Comment / uncomment lines
Ctrl SpaceCtrl Space Autocomplete
Ctrl EnterCtrl Enter Reset layout
⌘ ⌥ [ / ⌘ ⌥ ]Ctrl ⇧ [ / Ctrl ⇧ ] Fold / unfold block
Code
The editor didn't load — try refreshing the page. Navigation, shortcuts and the info panel still work in the meantime.
Preview
Dimensions0 × 0
Delay
Console