let number = 5;
console.log(number);
Output
5
function addNumbers (n1, n2) {
let result = n1 + n2;
console.log(result);
}
addNumbers(4, 9);
Output
13
function addNumbers (n1, n2) {
let result = n1 + n2;
console.log(result);
}
addNumbers(4, 9);
console.log(result);
Output
ReferenceError: Can't find variable: result
function addNumbers (n1, n2) {
let result = n1 + n2;
console.log(result);
}
addNumbers(4, 9);
let result = 123;
console.log(result);
Output
13
123
let result;
function addNumbers (n1, n2) {
result = n1 + n2;
}
addNumbers(4, 9);
console.log(result);
Output
13
let message = "hello";
function greet() {
message = "How are you?"
}
// before the function call
console.log(message);
greet();
//after the function call
console.log(message);
Output
hello
How are you?
const addNumbers = (n1, n2) => {
let result = n1 + n2;
console.log(result);
if (result > 10) {
let result1 = "Positive";
console.log(result1)
}
}
addNumbers(4, 9);
Output
13
Positive
const addNumbers = (n1, n2) => {
let result = n1 + n2;
console.log(result);
if (result > 10) {
let result1 = "Positive";
console.log(result1)
}
console.log(result1);
}
addNumbers(4, 9);
Output
13
Positive
ReferenceError: Can't find variable: result1
Q. What is the output of the program?
let a = 88;
function checkValue() {
let a = 77;
a = a - 57;
}
checkValue();
console.log(a);
- 88
- 77
- 20
- 31
Answer: 1