DEV Community

VIDHYA VARSHINI
VIDHYA VARSHINI

Posted on

Day 4 in JavaScript

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;
}
Enter fullscreen mode Exit fullscreen mode

Ex:

function add(a, b) {
  return a + b;
}

let result = add(15, 36);
console.log(result);
Enter fullscreen mode Exit fullscreen mode

Output:41

function makeBiriyani(container) {
    console.log(container);
    console.log(makeBiriyani);
    return"Biriyani";
}
let plate= makeBiriyani("rice");
console.log(plate);
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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>
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)