parajulirajesh.com.np

Write a js code to find a factorial of a given number?

<!DOCTYPE html>
<html>
<body>
<script>
function factorial(n) {
if (n == 0)|| (n==1)
return 1;
else
return n * factorial(n – 1);
}
let num = 5;
document.write(“Factorial of a given number is ” + factorial(num));
</script>
</body>
</html>

Write a function to enter two numbers and find the sum of two numbers in javascript.

<!DOCTYPE html>
<html>
<body>
<script>
function sum(a, b) {
return a + b;
}
let num1 = parseInt(prompt(“Enter a value: “));
let num2 = parseInt(prompt(“Enter another value: “));
let add=sum(num1,num2);
document.write(“Sum is ” +add);
</script>
</body>
</html>

Difference between server-side and client side scripting?

Server-Side ScriptingClient-Side Scripting
Runs on the server computerRuns on your browser (your computer)
Example: PHP, PythonExample: JavaScript
User cannot see the codeUser can see the code
Can work with databasesCannot work with databases
Makes web pages ready for userChanges web page after it shows up
Slower because server does the workFaster because your computer does the work
Used for back-end.Used for front-end.
More secureLess secure

Explain different tpes of data types used n javascript

Datatype refers to the type of data.
Types of Data Types in JavaScript:

Number – Used to store numeric values (e.g., 10, 3.14)
let x=10;
let y=10.5;
String – Used to store text inside quotes (e.g., “Hello”, ‘JS’)
let name=”rajesh”;
let program=’javascript’;
Boolean – Stores only two values: true or false
let isStudent = true;
let hasLogin = false;
Undefined – A variable that is declared but has no value yet
let x;
Null – Represents an empty value
let abc=null;
Object – Stores data in key-value pairs (e.g., {name: “Alice”, age: 20})
let person = {name: “Bob”, age: 25};
Array – A type of object that stores multiple values in a list (e.g., [1,2,3])
let fruits = [“Apple”, “Banana”, “Mango”];

Scroll to Top

Rajesh Parajuli

BICTE GMC

LEC.RAJESH PARAJULI

Address: Ghodaghodi Municipality-1 Sukhad kailali

Contact: 9847546279

Ghodaghodi Multiple Campus BICTE