Javascript Tutorial 08 Functions

Accessing a function without () will return the function definition instead of the function result:

function toCelsius(fahrenheit) {
    return (5/9) * (fahrenheit-32);
}
document.getElementById("demo").innerHTML = toCelsius;  // function toCelsius(f) { return (5/9) * (f-32); }

Javascript Tutorial 07 Datatypes

Primitive types:

  • string
  • number
  • boolean
  • null
  • undefined

Complex types:

  • function
  • object

In JavaScript arrays are objects.

undefined

In JavaScript, a variable without a value, has the value undefined. The typeof is also undefined.

var person; // Value is undefined, type is undefined

null

In JavaScript null is “nothing”. It is supposed to be something that doesn’t exist.

Unfortunately, in JavaScript, the data type of null is an object.

You can consider it a bug in JavaScript that typeof null is an object. It should be null.

var person = null;  // Value is null, but type is still an object

Difference Between Undefined and Null

typeof undefined           // undefined
typeof null                // object
null === undefined         // false
null == undefined          // true

JavaScript evaluates expressions from left to right. Different sequences can produce different results:

var x = 16 + 4 + "Volvo"; // 20Volvo
var y = "Volvo" + 16 + 4; // Volvo164

JavaScript has dynamic types. This means that the same variable can be used to hold different data types:

var x;            // Now x is undefined
var x = 5;        // Now x is a Number
var x = "John";   // Now x is a String

Javascript Tutorial 06 Operators

Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object type