Multiple choice technology web technology

What is the output of the alert function for the below lines of code? var sum, Sum; sum = 0; alert(Sum);

  1. 0

  2. undefined

  3. Exception(0365): object undefined!

  4. Javascript error in the browser

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

JavaScript is case-sensitive, so 'sum' and 'Sum' are two completely different variables. The code only assigns a value to 'sum', leaving 'Sum' uninitialized. When alert(Sum) is called, it outputs 'undefined' because the variable Sum was never assigned a value.