JavaScript -Functions



This content originally appeared on DEV Community and was authored by Dharshini E

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
}

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

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

console.log("welcome!");

typeof – its used to find “which type of data is given”.
example:

let name ="dharshini";
console.log(typeof name);

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;

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

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);

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");

happy codding!


This content originally appeared on DEV Community and was authored by Dharshini E