/JavaScript

JavaScript is one of the 3 languages all web developers must learn: 1. HTML to define the content of web pages 2. CSS to specify the layout of web pages 3. JavaScript to program the behavior of web pages

Primary LanguageJavaScript

JavaScript

JavaScript is one of the 3 languages all web developers must learn:

  1. HTML to define the content of web pages
  2. CSS to specify the layout of web pages
  3. JavaScript to program the behavior of web pages

JavaScript Data Types

  • Number - 1,2,3...
  • String - 'Hi Yash'
  • Boolean - true/ false
  • Null - Explicitly set a variable with no value
  • Undefined - For variables that have not yet been defined
  • Object - Complex data structures - Arrays, Dates...
  • Symbol - Used with objects

Few Fundamentals In JS

HTML Template


let result = `${title} ${names} ${message}`;
console.log(result);
let html = `

${title}

${names}

${message}`; console.log(html);

Strict Comparison (Different Types Cannot Be Equal)


//Strict Comparison
let ageIs=25;
console.log(ageIs===25);
console.log(ageIs==='25');
console.log(ageIs!==25);
console.log(ageIs!=='25');

//Type Conversion
let val ='100';
console.log(typeof val);
val=Number(val);
console.log(val+1);
console.log(typeof val);

Function

Function Declaration

Function Declaration can be hosted


//Function Declaration
function greet(){
    console.log("Hello Yashwanth");
}

Function Expression

Function Declaration cannot be hosted


//Function Expression
const speak =function()
{
    console.log("Good Day");
};

greet();
speak();

Arguments & Parameters


//Arguments & Parameters
const speak =function(firstName='Yash',lastName='Yashz')
{
    console.log(`Good Day ${firstName},${lastName}`);
};

speak();
speak('Yashwanth','Parameswaran');

Returning of Values

Regular Function


const calcArea=function(radiusArea)
{
    return 3.14 * radiusArea **2;
}

const area= calcArea(5);
console.log(area);

Arrow Function


const calcArea=radiusArea => {
    return 3.14 * radiusArea **2;
}

const area= calcArea(5);
console.log(area);

const greet = () => 'Hello, World';
greet();