JavaScript examples

JavaScript is a browser-based scripting language. With JavaScript, you add behavior to the HTML documents and control the browser or change the HTML document.


The best way to learn JavaScript is to try many examples. JavaScript is also a complex programming language, it is not easy to learn JavaScript just because it is a browser language. You must practice lots of examples.

The examples are divided broadly into two categories – basic examples and object-oriented examples. The basic example demonstrates the fundamental concepts of JavaScript and object-oriented examples, you learn about object-oriented programming concepts.

Prerequisites

You need to complete certain prerequisites to get started with JS examples. These are tools and learning resources to help you learn JavaScript efficiently.

  • JavaScript tutorial – you must be familiar with JavaScript concepts and the best way to learn is either visit our JavaScript tutorial page or get a good easy to follow JavaScript book with examples.
  • Notepad – to write programs you need a text editor and browser can interpret the scripts easily. Download a new editor like Bracket, Sublime Text, Notepad++ or use builtin text editors – Notepad or Text Edit in Mac.
  • Browser – you need to install a browser to test you JavaScript code. You can download free browsers from internet like Chrome, Mozilla Firefox, UC Browser, Microsoft Edge, etc.

JavaScript basic exercises

This section contains a list of common JavaScript exercises.

JavaScript BasicsJavaScript Objects
Ex01: First ScriptEx13: Objects
Ex02: Output To HTMLEx14: Functions
Ex03: Alert BoxesEx15: Nested Objects
Ex04: External JavaScriptEx16: Array Of Objects
Ex05: Variable DeclarationJavaScript Projects
Ex06: Conditional StatementsDecimal To Binary Converter
Ex07: Switch-CaseBinary To Decimal Converter
Ex08: Alert Confirm, and PromptJavaScript Algorithms
JavaScript LoopsCelsius To Fahrenheit Conversion
Ex09: For LoopFind Factorial of a Number
Ex10: While LoopReverse a String
Ex11: Do-While LoopFind Longest Word In A String
JavaScript ArraysFind Largest Number In Arrays
Ex12: Arrays