Keywords in Dart

·

3 min read

Cover Image for Keywords in Dart

Knowledge of keywords is also important. As we cannot use it as Identifiers (Although in some cases we can. let’s follow the best practices).

Keywords have a special meaning in the language.

Reserved Words

  • Following are the reserved words in a dart. These reserved words cannot be used as identifiers.
assertdefaultfinally
trybreakdo
returnvarcase
ifsupervoid
enuminswitch
classextendsis
withconstfalse
throwcontinuefinal
truerethrowfor
elsecatchwhile
thisnewnull

Contextual Keywords

  • These keywords have meaning only in specific places. In other places, they are valid identifiers.
asyncshowhide
syncon

Built-in Identifiers

  • These keywords are valid identifiers in most places, but they can’t be used as class or type names, or as import prefixes.
abstractdynamicFunctioninterface
partasexportget
librarysetcovariantexternal
implementsmixinstaticdeferred
factoryimportoperatortypedef

await*andyieldare newer words added after Dart’s 1.0 release. And cannot be used as an identifier in any function body marked with async, async*, or sync*.*

These all are keywords of a dart. That you need to know as a developer. Don’t use any one of these as an identifier (Although you can. Just take it as my personal tip☺️)

Conclusion

In conclusion, understanding the significance of keywords in Dart is crucial, as they cannot be used as identifiers in general (with some exceptions). Keywords hold a specific meaning within the language and should be recognized as such. Dart includes reserved words that cannot be used as identifiers, along with contextual keywords that have meaning only in specific contexts. Built-in identifiers are valid in most instances, except as class or type names, or as import prefixes. Lastly, the newer keywords "await" and "yield" has certain limitations and cannot be used as identifiers in function bodies marked with async, async*, or sync*.

Feel free to let me know if I miss something. And I’ll surely catch you up in the next article.

Till Then Keep Coding, Keep Loving. Jai Hind, Vande Mataram 🇮🇳

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitant that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

💡
Subscribe To My Newsletter For More Such Content.

Learn More about Dart and Flutter

Follow me for more such content