[#]: subject: (Write your first JavaScript code) [#]: via: (https://opensource.com/article/21/7/javascript-cheat-sheet) [#]: author: (Seth Kenlon https://opensource.com/users/seth) [#]: collector: (lujun9972) [#]: translator: (lixin555) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) Write your first JavaScript code ====== JavaScript was created for the web, but it can do so much more. Learn the basics, then download our cheat sheet so you always have the details at hand. ![Code with javascript on white background][1] JavaScript is a programming language full of pleasant surprises. Many people first encounter JavaScript as a language for the web. There's a JavaScript engine in all the major browsers, there are popular frameworks such as JQuery, Cash, and Bootstrap to help make web design easier, and there are even programming environments written in JavaScript. It seems to be everywhere on the internet, but it turns out that it's also a useful language for projects like [Electron][2], an open source toolkit for building cross-platform desktop apps with JavaScript. JavaScript is a surprisingly multipurpose language with a wide assortment of libraries for much more than just making websites. Learning the basics of the language is easy, and it's a gateway to building whatever you imagine. ### Install JavaScript As you progress with JavaScript, you may find yourself wanting advanced JavaScript libraries and runtimes. When you're just starting, though, you don't have to install JavaScript at all. All major web browsers include a JavaScript engine to run the code. You can write JavaScript using your favorite text editor, load it into your web browser, and see what your code does. ### Get started with JavaScript To write your first JavaScript code, open your favorite text editor, such as [Notepad++][3], [Atom][4], or [VSCode][5]. Because it was developed for the web, JavaScript works well with HTML, so first, just try some basic HTML: ``` <[html][6]>   <[head][7]>     <[title][8]>JS</[title][8]>   </[head][7]>   <[body][9]>     <[p][10] id="example">Nothing here.</[p][10]>   </[body][9]> </[html][6]> ``` Save the file, and then open it in a web browser. ![HTML displayed in browser][11] (Seth Kenlon, [CC BY-SA 4.0][12]) To add JavaScript to this simple HTML page, you can either create a JavaScript file and refer to it in the page's `head` or just embed your JavaScript code in the HTML using the `