JSFiddle - React, Tailwind, and code Playground

by Sunny SM

JavaScript

function getMonth(month){
    month = month-1;
    var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    
    if(months[month] != null){
        return months[month];
    }else{
        throw "Invalid Month No";
    }
}

try{
    monthName = getMonth(8);
    alert("Month Is : " + monthName);
}catch(e){
    console.log(e);
}