Objects Introduction

JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define your own objects and make your own variable types.

Object - is just a special kind of data. It has properties and methods.
Properties - are the values associated with an object. (i.e.:length property of the String object)
<script type="text/javascript">
  var txt="Hello World!"
  document.write(txt.length)
</script>
Output: 12 (number of characters returned)
Methods - are the actions that can be performed on objects. (i.e.:toUpperCase() method of the String object)
<script type="text/javascript">
  var txt="Hello World!"
  document.write(txt.toUpperCase())
</script>
Output: HELLO WORLD! (txt in uppercase returned)

String

var txt="Harry Roland Kunz"

indexOf() method - returns the position of the first occurrence of a specified string value in a string.

<script type="text/javascript">
  var str="Hello world!"
  document.write(str.indexOf("Hello") + "<br />")  Output: 0
  document.write(str.indexOf("World") + "<br />")  Output:-1
  document.write(str.indexOf("world"))             Output: 6
</script>

match() method - searches for a specified string value within a string and returns the string value if found

<script type="text/javascript">
var str="Hello world!"
  document.write(str.match("world") + "<br />")    Output: world
  document.write(str.match("World") + "<br />")    Output: null
  document.write(str.match("worlld") + "<br />")   Output: null
  document.write(str.match("world!"))              Output: world!
</script>
Click this link for a COmplete String Object Reference

Date

<script type="text/javascript">
  document.write(Date())
Output: var minutes = 1000*60 var hours = minutes*60 var days = hours*24 var years = days*365 var d = new Date() var t = d.getTime() var y = t/years document.write("It's been: " + y + " years since 1970/01/01!")
Output:
<script type="text/javascript">
var d = new Date()
d.setFullYear(1992,10,3)
document.write(d)
</script>
Output: document.write (d.toUTCString()) Output: