Home > Browser, Interview Questions, JavaScript, Tips & Tricks > Javascript boolean interpretation

Javascript boolean interpretation

I have two simple questions for you about boolean values in Javascript.
When will browser show alert message:

        if (a-b) alert("it's true!");

And another one

What will be printed as result of running this script:

	for (var n=10; n; n-- )
	{
		document.write (n + ",");
	}

The answer for both questions relies on the same principle of what JavaScript engine will evaluate as true and what as false.

VN:F [1.9.22_1171]
Rating: 5.0/5 (5 votes cast)
Javascript boolean interpretation, 5.0 out of 5 based on 5 ratings
  1. Mahesh
    August 13th, 2009 at 08:56 | #1

    1.

    If (a-b) is non zero, then “It’s true” alert message is displayed.
    If value a and b is same, (a-b) evaluates to 0, then no alert message.

    VA:F [1.9.22_1171]
    Rating: 5.0/5 (1 vote cast)
  2. December 28th, 2009 at 14:12 | #2

    Сheck the variable is always the equivalent of comparing a variable to null

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
  3. June 1st, 2010 at 00:06 | #3

    If only I had a buck for each time I came to kossovsky.net! Amazing post.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
  1. No trackbacks yet.

Subscribe without commenting

SEO Powered by Platinum SEO from Techblissonline
watch free movies