0% found this document useful (0 votes)
5 views

Java Script Functions

This document describes 20 JavaScript functions including parseInt(), parseFloat(), console.log(), Math functions, and the Date object. It provides the definition, syntax, and examples of using each function.

Uploaded by

vodnala srujana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Script Functions

This document describes 20 JavaScript functions including parseInt(), parseFloat(), console.log(), Math functions, and the Date object. It provides the definition, syntax, and examples of using each function.

Uploaded by

vodnala srujana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Java Script Functions

1. parseInt(): Parses a string and returns an integer.


2. parseFloat(): Parses a string and returns a floating point number.
3. console.log(): Outputs messages to the console.
4. function(): Keyword to declare a function.
5. functionName(): Syntax to call a function.
6. return: Statement to explicitly return a value from a function.
7. arguments: Array-like object representing function arguments.
8. length: Property of the arguments object to determine the number of
arguments.
9. if statement: Conditional statement to execute code based on a condition.
10.for loop: Iterates over a block of code a number of times.
11.typeof: Operator to determine the type of a variable.
12.isNaN(): Function to determine if a value is NaN (Not a Number).
13.Array.isArray(): Function to determine if a value is an array.
14.Math.random(): Returns a random floating-point number between 0 and
1.
15.Math.floor(): Rounds a number down to the nearest integer.
16.Math.ceil(): Rounds a number up to the nearest integer.
17.Math.max(): Returns the highest-valued number in a list of arguments.
18.Math.min(): Returns the lowest-valued number in a list of arguments.
19.String(): Converts a value into a string.
20.Date(): Creates a new Date object.

============================InDetail==============================
1. parseInt():
• Definition: Parses a string and returns an integer.
• Syntax: parseInt(string, radix)
• Example:
let str = "123";
let num = parseInt(str);
console.log(num); // Output: 123
2. parseFloat():
• Definition: Parses a string and returns a floating point number.
• Syntax: parseFloat(string)
• Example:
let str = "3.14";
let num = parseFloat(str);
console.log(num); // Output: 3.14
3. console.log():
• Definition: Outputs messages to the console.
• Syntax: console.log(value1, value2, ..., valueN)
• Example:
console.log("Hello, world!");
4. function():
• Definition: Keyword to declare a function.
• Syntax: function functionName(parameters) { // function body }
• Example:
function greet(name)
{
console.log("Hello, " + name + "!");
}
5. functionName():
• Definition: Syntax to call a function.
• Syntax: functionName(arguments)
• Example:
greet("Alice");
6. return:
• Definition: Statement to explicitly return a value from a function.
• Syntax: return expression;
• Example:
function add(a, b) { return a + b; }
7. arguments:
• Definition: Array-like object representing function arguments.
• Syntax: arguments[index]
• Example:
function sum()
{
let total = 0;
for (let i = 0; i < arguments.length; i++)
{
total += arguments[i];
}
return total;
}
8. length:
• Definition: Property of the arguments object to determine the
number of arguments.
• Syntax: arguments.length
• Example:
function countArgs()
{
return arguments.length;
}
9. if statement:
• Definition: Conditional statement to execute code based on a
condition.
• Syntax: if (condition) { // code block }
• Example:
let num = 10;
if (num > 0) {
console.log("Number is positive");
}
10.for loop:
• Definition: Iterates over a block of code a number of times.
• Syntax: for (initialization; condition; iteration) { // code block }
• Example:
for (let i = 0; i < 5; i++)
{
console.log(i);
}
11.typeof:
• Definition: Operator to determine the type of a variable.
• Syntax: typeof variable
• Example:
let x = 10;
console.log(typeof x); // Output: "number"
12.isNaN():
• Definition: Function to determine if a value is NaN (Not a
Number).
• Syntax: isNaN(value)
• Example:
console.log(isNaN("Hello")); // Output: true
13.Array.isArray():
• Definition: Function to determine if a value is an array.
• Syntax: Array.isArray(value)
• Example:
let arr = [1, 2, 3];
console.log(Array.isArray(arr)); // Output: true
14.Math.random():
• Definition: Returns a random floating-point number between 0
and 1.
• Syntax: Math.random()
• Example:
console.log(Math.random()); // Output: 0.12345 (random
number)
15.Math.floor():
• Definition: Rounds a number down to the nearest integer.
• Syntax: Math.floor(number)
• Example:
console.log(Math.floor(3.7)); // Output: 3
16.Math.ceil():
• Definition: Rounds a number up to the nearest integer.
• Syntax: Math.ceil(number)
• Example:
console.log(Math.ceil(3.2)); // Output: 4
17.Math.max():
• Definition: Returns the highest-valued number in a list of
arguments.
• Syntax: Math.max(value1, value2, ..., valueN)
• Example:
console.log(Math.max(5, 10, 2)); // Output: 10
18.Math.min():
• Definition: Returns the lowest-valued number in a list of
arguments.
• Syntax: Math.min(value1, value2, ..., valueN)
• Example:
console.log(Math.min(5, 10, 2)); // Output: 2
19.String():
• Definition: Converts a value into a string.
• Syntax: String(value)
• Example:
let num = 123;
console.log(String(num)); // Output: "123"
20.Date():
• Definition: Creates a new Date object.
• Syntax: new Date()
• Example:
let currentDate = new Date();
console.log(currentDate); // Output: current date and time

NodeJs Assignment by:


V.Srujana
22JJ1A0563-CSE

You might also like