When we should use $(document).ready(function(){ in our jquery program?

When we should use $(document).ready(function(){ in our jquery program?

Hi

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.each demo</title>
<style>
div {
color: blue;
}
div#five {
color: red;
}
</style>
<script src="jquery-1.11.0.min.js"></script>
</head>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
<div id="five"></div>
<script>
var arr = [ "one", "two", "three", "four", "five" ];
var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };
jQuery.each( arr, function( i, val ) {
$( "#" + val ).text( "Mine is " + val + "." );
// Will stop running after "three"
return ( val !== "three" );
});
jQuery.each( obj, function( i, val ) {
$( "#" + i ).append( document.createTextNode( " - " + val ) );
});

</script>
</body>
</html>


This program is running successfully without using $(document).ready(function(){  . I have a thought that for every program to execute you should use either  $(document).ready(function(){  or  use $(window).load(function() {, but here we are using none.

When we should use $(document).ready(function() {  in our program.Please Let me know!!

Thanks
Varun