Identifiers in Dart
In Dart, identifiers are used to name variables, functions, classes, methods, parameters, and other components in your code. These names can include letters, digits, underscores (_), and dollar signs ($), but they must adhere to specific rules for valid naming
📅 Tue Jan 14 2025⏱ 2 min
.png)
Identifiers can consist of :
* Uppercase letters (A-Z) * Lowercase letters (a-z) * Digits (0-9), but cannot start with a digit * The underscore character (_) * The dollar sign ($)
Identifiers must follow these rules :
1. First character: The first character of an identifier must be a letter (either uppercase or lowercase) or an underscore (_). * Incorrect: 1stName, 9thRoll * Correct: _firstName, name1 2. Cannot start with a digit: Identifiers cannot start with a number. * Incorrect: 123abc, 9students * Correct: abc123, students9 3. No special characters except _ and $: * Incorrect: @name, name! * Correct: name_1, price$ 4. No successive underscores (__): You cannot use consecutive underscores. * Incorrect: my__variable * Correct: my_variable 5. Unique identifiers: Each identifier in a program must be unique. You cannot use the same name for more than one variable, function, or class in the same scope. 6. Case sensitive: Dart is case-sensitive, which means name, Name, and NAME are three different identifiers. * Incorrect: Name = name (as they are different) * Correct: Name is different from name. 7. No whitespace allowed: Identifiers cannot have spaces. * Incorrect: my name, total amount * Correct: myName, totalAmount
Example :
Let's break down a basic Dart program to explain identifiers.
void main() {
var name = "DevEraa"; // 'name' is an identifier
var roll_no = 24; // 'roll_no' is an identifier
print("My name is ${name}. My roll number is ${roll_no}.");
}
Related Posts
What is Flutter...??
Flutter is an open-source UI software development kit for building natively compiled applications for mobile, web, and desktop from a single codebase. It works on the Dart programming language and is famous for developing fast, expressive and flexible UIs and high performance output.
2 min
What is Dart in Flutter..??
Dart is the programming language which Flutter adopted to build a cross-platform application. Google has developed this language and optimized in UI, and it is suitable for the fast development of visually rich applications on Flutter.
2 min
What is main in Flutter...??
Every programming language has an entry point from which the main execution of the code begins. Dart has this point with the main() function-that is where the program first looks to start executing code.
2 min
What is print()..??
The print statement is used in Dart to display output to the console. It is very helpful for debugging so you can see the value of variables or whether particular parts of your code are running as you expect them to.
2 min
What are the comments in Dart?
Comments are used to explain and add notes in code. The compiler ignores the commented code during the time of execution of the program.
2 min
Semicolon in Dart
In Dart, a semicolon (;) is used to terminate a statement. It signals the end of the statement and is essential for proper code execution. Without a semicolon, the code will produce a syntax error.
5 min