How can I check whether an id existed?

How can I check whether an ID existed in the current page? I want to use
the $('id').getValue() to get the field value. But sometimes the ID may
not exist.

if($('id')){
  val = $F('id')
}