You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.4.2 and below of the Javascript SDK. Go to our current docs, or see our Web migration guide.

Version 2.4.2Changelog

DataSnapshot.val()

Depending on the data in a DataSnapshot, the val() method may return a primitive (string, number, or boolean), an array, or an object. It may also return null, indicating that the snapshot is empty and contains no data.

The export format differs depending on what type of data is being read. In the case of primitive values (a string, number, or boolean), a primitive value is returned:

ref.set("hello", function(error) {
  ref.once("value", function(snapshot) {
    var data = snapshot.val();
    // data === "hello"
  });
});

In the case of reading data that is a JavaScript object, a JavaScript object is returned:

ref.setWithPriority({ name: "Fred", age: 53 }, function(error) {
  ref.once("value", function(snapshot) {
    var data = snapshot.val();
    // data is { "name": "Fred", "age": 53 }
    // data.name === "Fred"
    // data.age === 53
  });
});

If you want priority information to be included in the snapshot's data, you should use the exportVal() method.