show javascript info if no variable exsist

I have a page on my website and I want it to  print a string if a variable doesn't exsist if the variable does exsist then I want it to print the variable instead something like

if showstring = null then
document.write("variable doesn't exsist")
end if

I am not really good with javascript so I could really use the help thanks ahead a time
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

would be something like this...

    document.write("variable doesn't exsist");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Maybe a nicer way :

if (typeof(showstring)=="undefined") document.write("variable doesn't exsist");
else document.write(showstring);

This check if variable is undefined.
Pravin AsarPrincipal Systems EngineerCommented:
Here is very generic way to handle Error, by assigning onError event handler for a document.

<title>Catch error </title>

<script language="javascript">
function handleErr(err)
txt="There was an error on this page.\n\n"
txt+="Error: " + err + "\n"
return true
alert ('Message  ' + myundefinedvar);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.