JavaScript Keywords, Identifiers, and Variable

JavaScript Keywords

JavaScript keywords are reserved words that have special meaning to the JavaScript interpreter. Keywords cannot be used as variable names or function names.

Here are some examples of JavaScript keywords:

  • var
  • let
  • const
  • function
  • if
  • else
  • while
  • for
  • do
  • switch
  • case
  • default

JavaScript Identifiers

JavaScript identifiers are names that are used to identify variables, functions, and other objects in JavaScript code. Identifiers must start with a letter or underscore (_), and they can contain letters, numbers, and underscores.

Here are some examples of valid JavaScript identifiers:

  • myVariable
  • myFunction
  • _secretIdentifier

JavaScript Variables

A variable is a named location in memory that can store a value. Variables are used to store data that can be used later in the program.

To declare a variable in JavaScript, you use the var keyword. The following code declares two variables named firstName, age and assigns it the values Diana and 28:

let firstName = "Diana";
var age = 28;

Task

Declare a variable lastName using the let keyword and with the value Penty. Declare another variable PI using the const keyword and assign value 3.14159. Console log the variable lastName. Run the code and experiment with the code to get used to it.


				
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT