Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Identifiers in JavaScript | JavaScript syntax
Introduction to JavaScript (staging)
course content

Conteúdo do Curso

Introduction to JavaScript (staging)

Introduction to JavaScript (staging)

1. Introduction
2. JavaScript syntax
3. Data Types and Variables

book
Identifiers in JavaScript

What are JavaScript Identifiers

An identifier is simply a name. Identifiers are names given to entities like variables, arrays, functions, classes, etc. In programming, we often store some values in some variables for later use, and for this, we give some names to variables.

Rules for naming Identifier

  • Identifier names must start with a letter, an underscore _, or with a dollar sign $.
1234567891011
//valid identifier name let greeting="hello world"; console.log(greeting); //valid identifier name let _greeting="Good night"; console.log(_greeting); //valid identifier name let $greeting="Good morning"; console.log($greeting);
copy

We got the output without any error which means that all our identifiers are according to JavaScript naming rules.

  • Identifier names cannot start with a number.
1
let 1number=10;
copy

If you run the code you can see the output says SyntaxError: Invalid or unexpected token which means that the token or the identifier we have used is invalid.

  • JavaScript is case-sensitive i.e. greeting is different from Greeting.
1234567
//different identifier name from below let Greeting ="hello world"; console.log(Greeting); //valid identifier name from above let greeting="good morning"; console.log(greeting);
copy

Note: JavaScript reserves certain identifiers for use by the language itself. These reserved words cannot be used as regular identifiers. We'll consider it later.

Tarefa
test

Swipe to show code editor

In the given javascript code rules for naming, identifiers are violated. Change the following names to make them correct. Then show the values on the console.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
toggle bottom row

book
Identifiers in JavaScript

What are JavaScript Identifiers

An identifier is simply a name. Identifiers are names given to entities like variables, arrays, functions, classes, etc. In programming, we often store some values in some variables for later use, and for this, we give some names to variables.

Rules for naming Identifier

  • Identifier names must start with a letter, an underscore _, or with a dollar sign $.
1234567891011
//valid identifier name let greeting="hello world"; console.log(greeting); //valid identifier name let _greeting="Good night"; console.log(_greeting); //valid identifier name let $greeting="Good morning"; console.log($greeting);
copy

We got the output without any error which means that all our identifiers are according to JavaScript naming rules.

  • Identifier names cannot start with a number.
1
let 1number=10;
copy

If you run the code you can see the output says SyntaxError: Invalid or unexpected token which means that the token or the identifier we have used is invalid.

  • JavaScript is case-sensitive i.e. greeting is different from Greeting.
1234567
//different identifier name from below let Greeting ="hello world"; console.log(Greeting); //valid identifier name from above let greeting="good morning"; console.log(greeting);
copy

Note: JavaScript reserves certain identifiers for use by the language itself. These reserved words cannot be used as regular identifiers. We'll consider it later.

Tarefa
test

Swipe to show code editor

In the given javascript code rules for naming, identifiers are violated. Change the following names to make them correct. Then show the values on the console.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt