DEV Community

sai sanjana
sai sanjana

Posted on

Javascript- literals and keywords

Hi all,
--JavaScript Literals
Literals are the simplest way to represent values in JavaScript. They are written directly into the program without needing computation.

Types of Literals
Number literals: Represent numeric values. Example: 42, 3.14.

String literals: Text enclosed in quotes. Example: "Hello", 'World'.

Boolean literals: Logical values true or false.

Null literal: Represents an empty or non-existent value. Example: null.

Undefined literal: Indicates a variable has been declared but not assigned.

Object literals: Define objects directly.

Array literals: Define lists of values. Example: [1, 2, 3].

--JavaScript Keywords
Keywords are reserved words that cannot be used as variable names or identifiers because they have predefined roles in the language.

Categories of Keywords
Declaration keywords: var, let, const — used to declare variables.

Control flow keywords: if, else, switch, case, default.

Looping keywords: for, while, do, break, continue.

Function-related keywords: function, return, yield.

Class and object keywords: class, extends, new, this, super.

Error handling keywords: try, catch, finally, throw.

Asynchronous keywords: async, await.

-Literals provide the raw data that programs manipulate.

-Keywords define the structure, flow, and rules of the program.
Together, they ensure JavaScript code is both meaningful and executable. Misusing keywords (like naming a variable return) leads to syntax errors, while incorrect literals cause logic issues.

Literals and keywords are the backbone of the language. Literals give us values to work with, while keywords provide the grammar to organize those values into meaningful instructions.

Top comments (0)