Keywords in JavaScript
Below is the list of keywords in JavaScript:
break, case, catch, class, const, continue, debugger, default, delete, do, else, enum, export, extends, false, finally, for, function, if, import, in, instanceof, new, null, return, super, switch, this, throw, true, try, typeof, var, void, while, with, yield
Example:
// function keyword
function gradeCalculator(score) {
if (score >= 90) {
return "A";
} else if (score >= 80) {
return "B";
} else if (score >= 70) {
return "C";
} else if (score >= 60) {
return "D";
} else {
return "F";
}
}
// const keyword
const myScore = 85;
const letterGrade = gradeCalculator(myScore);
console.log("Your grade is:", letterGrade);
// new keyword
const currentDate = new Date();
console.log("Today's date:", currentDate);
// Switch, case and default keyword
let day = 3;
switch (day) {
case 0:
console.log("Sunday");
break;
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
case 3:
console.log("Wednesday");
break;
default:
console.log("Invalid day number");
}
Output
Your grade is: B Today's date: 2024-06-04T09:43:50.196Z Wednesday
Keywords are the foundational elements of programming languages, defining the syntax and structure. They are reserved words with specific meanings, crucial for writing clear and effective code. Understanding and correctly using keywords is fundamental to mastering any programming language.
What is Keyword in Programming?
Keywords are predefined or reserved words that have special meaning to the compiler. In this article, we will discuss about keywords in programming, its importance, and usage in different languages.
Contact Us