Javascript: A loosely typed language

This entry is part 9 of 27 in the series Javascript Tutorial

JavaScript is a loosely typed language, which means you do not declare the data types of variables explicitly.

In many cases JavaScript performs conversions automatically when they are needed.

You can use var to define string or integer, which are commonly used in Javascript.

<!DOCTYPE html>
   function updateFunction()
     var new_str = "I am a new string";
     var new_int = 15;


  <h4>I am a string</h4>
  <p>I will be an integer</p>
 <button onclick="updateFunction()">Click Me</button>


The script above illustrates some important concepts about Javascript.

First, we can see that a variable can accept either a string or an integer. For a string, we need to use “” but not for integer.

In designing a web site using Javascript, it is always about accessing the DOM and updating it. In this case, we are accessing the <h4> and <p> tags and change the content inside the 2 tags.

We change them using


Notice the [0] in both statements, these are related to array variables and will be explained in the later posts.

Series Navigation<< Javascript: Alert
Javascript: Global variables >>