What is Javascript?

Javascript is a scripting or programming language which can be used to create dynamic web pages. It is used in most of the Web Browsers. It is used in Web development. Javascript can be used to add behaviour to button click events.

Javascript Math

// function to find square root of any number
function findSquateRoot(number) {
    const res = Math.sqrt(number);
    console.log(res);
  }

  findSquateRoot(4) 
  findSquateRoot(100)
2
10
// function to add two numbers and print to console
function addNumbers(num1, num2) {
    sum = num1 + num2
    console.log(sum);
  }

  addNumbers(10, 20)
  addNumbers(30, 40)
30
70
// function to return product of two numbers
function findProduct(num1, num2) {
    return num1 * num2
  }

  findProduct(10, 20)
200

Javascript Date Functions

//Date function to print current date and time in Pacific Timezone
const date_1 = new Date();
console.log("Current Date and Time: "+d);
Current Date and Time: Mon Sep 26 2022 07:05:13 GMT-0700 (Pacific Daylight Time)
//Date function to print current date and time in Indian Standard Time
const date_2 = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
console.log("Current Date and Time: "+d2);
Current Date and Time: 9/26/2022, 7:49:26 PM

Javascript Using String functions

//Using length function to find length of a word
let word_1 = "Sreeja Journal!";
let length_1 = text.length;
console.log("Word length: "+length_1 );
Word length: 15
//Javascript escaping
let word_4 = "Sreeja\'s Blog."
console.log(word_4);
Sreeja's Blog.