JavaScript example


  • Output text with JavaScript

  • Change HTML elements with JavaScript

  • An external JavaScript

  • Example analysis

JavaScript statements, comments and code blocks

  • JavaScript Statement

  • JavaScript code block

  • JavaScript single-line comment

  • JavaScript multi-line comment

  • Use single-line comments to prevent execution

  • Use multi-line comments to prevent execution

  • Example Parsing

JavaScript variables

  • Declare a variable, assign a value to it, and then display it

  • Example analysis

JavaScript conditional statement If ... Else

  • If statement

  • If...else statement

  • Random link

  • ##Switch statement


  • Example analysis

JavaScript message box

  • Alert (warning) box

  • Warning box with line breaks

  • Confirmation box

  • Prompt box


  • Example analysis

JavaScript function

  • Function

  • Function with parameters

  • Function with parameters 2

  • Function that returns a value

  • Function with parameters and return value

  • Example analysis

JavaScript loop

  • For loop

  • Loop output HTML title

  • While loop

  • Do while loop

  • break statement

  • continue statement

  • Use For.. .In statement to traverse the elements in the array

  • Instance analysis

JavaScript event

  • onclick event

  • onmouseover event

  • Instance analysis

JavaScript error handling

  • try...catch statement

  • try...catch statement with confirmation box

  • onerror event

  • Example analysis

Advanced JavaScript example

  • Create a welcome cookie

  • Simple timing

  • Another simple timing

  • Timing events in an infinite loop

  • Timing events in an infinite loop with a stop button

  • Use A clock made for timing events

  • Creating an instance of an object

  • Creating a template for an object