DEV Community

Dharshini E
Dharshini E

Posted on

JavaScript -Functions

1.what is function?
set of instruction perform specific task can be called multiple times optionally takes input as** parametters** and optionally returns values.
Functions significantly enhance code reusability by encapsulating specific functionalities into self-contained blocks.
This allows the same block of code to be invoked **multiple times **from different parts of a program.
function is a keyword.

syntax:

function functionName(parameter1, parameter2, ...) {

  return value; // Optional return statement
}
Enter fullscreen mode Exit fullscreen mode

functionName() -function calling statement
{ } - function definition

.log() - is a function , its created by javascript perdefined functions or inbuilt funtion.
example :

console.log("welcome!");
Enter fullscreen mode Exit fullscreen mode

typeof - its used to find "which type of data is given".
example:

let name ="dharshini";
console.log(typeof name);
Enter fullscreen mode Exit fullscreen mode

BigInt - datatype
BigInt variables are used to store big integer values that are too big to be represented by a normal JavaScript Number.
example:

let y = 9999999999999999n;
Enter fullscreen mode Exit fullscreen mode

What is return ?
The return statement stops the execution of a function and returns a value.

function myFunction(name) {
  return "Hello " + name;
}
console.log(myFunction("dharshini")); // Hello dharshini
Enter fullscreen mode Exit fullscreen mode

prompt()
In JavaScript, the prompt() method is a built-in function used to display a dialog box that prompts the user for input. This dialog box includes a message, a text input field, and "OK" and "Cancel" buttons.

Syntax :

result = prompt(message, defaultValue);
Enter fullscreen mode Exit fullscreen mode

alter()
In JavaScript, alert() is a global function used to display a modal dialog box with a specified message and an "OK" button. This dialog box pauses the execution of the script until the user clicks "OK".
example:

alert(" please enter vaild input");
Enter fullscreen mode Exit fullscreen mode

happy codding!

Top comments (0)