This content originally appeared on DEV Community and was authored by Bhuvana Sri R
What is return keyword ?
- The return statement stops the execution of a function and returns a value.
- It used for access the block scope variable outside.
What is BlockLeveScope?
The variable declare inside the block is called bloclevelscope.
It cant’t access the outside of the block.
Example:
function add(a,b)
{
total=a+b;
return total;
}
add(10,20)
What is GlobalLevelScope?
The variable was declare outside of the block.But it access both inside and outside of the block.
Example:
let total
function add(a,b)
{
total=a+b;
}
add(10,20)
console.log(total)
How to get UserInput ?
- Using prompt() Method we can get a userInput.
- prompt() is predefined or built-in function.
- It display a dialoge box.
- It return the value as the string formate.
- This dialog box includes a message, a text input field, and OK and Cancel buttons.
- If the user clicks OK after entering text, the prompt() method returns the entered text as a string.
- If the user clicks OK without entering any text, an empty string is returned.
- If the user clicks Cancel or closes the dialog box, null is returned. Example:
let a=prompt("enter the value")
if(a>=18)
{
console.log("Eligible for vote")
}
else
{
console.log("not Eligible for vote")
}
This content originally appeared on DEV Community and was authored by Bhuvana Sri R