Skip to content
Steve Perry edited this page Mar 13, 2016 · 1 revision

View the source code.

This document has a bunch of code examples that you can try in the Chrome developer tools console. In Chrome, press F12 to open the developer tools. Open the Console tab.

In the console, you can enter one line at a time or several lines at once.

When you enter one line at a time, you see the value of each expression you enter:

>  x = 5
<- 5
>  y = 3
<- 3
>  x + y
<- 8

To enter several lines, press SHIFT-ENTER between lines. Then press ENTER enter after the last line.

>  x = 5
   y = 3
   x + y
<- 8

Or paste a block of lines into the console.

>  function cube(n) {
     return n*n*n;
   }
   cube(5)
<- 125

JavaScript has these datatypes:

  • String
  • Number
  • Boolean
  • Null
  • Undefined
  • Object

The typeof function gives the type of a variable.

>  typeof x
<- "number"

Variables have properties and methods.

>  x.toString()
<- "5"

>  s = "Bob"
   s.length
<- 3
Clone this wiki locally