What is return keyword:
• The return keyword is used inside a function to exit the function.
• And it returns the value to the place where the function was called.
• The block level scope variable can be accessed outside.
Syntax:
function functionName() {
return value;
}
Ex:
function add(a, b) {
return a + b;
}
let result = add(15, 36);
console.log(result);
Output:41
function makeBiriyani(container) {
console.log(container);
console.log(makeBiriyani);
return"Biriyani";
}
let plate= makeBiriyani("rice");
console.log(plate);
Here, the output is Biriyani as it says to return "Biriyani".
Block level scope:
• The variables can be accessible inside the {} block where it is declared.
{
let a = 10;
const b = 20;
console.log(a); // 10
console.log(b); // 20
Prompt function:
The prompt() function is used to take input from the user through a popup box in the browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial scale=1.0">
<title>Document</title>
<script>
let age=18;{
if(0>17){
console.log("not eligible");
}
else{
console.log("eligible");
}
}
</script>
</head>
<body>
</body>
</html>
}
Top comments (0)