Skip to content

03 Constants

Sujal edited this page Aug 28, 2023 · 1 revision

Constants

In the world of Coda, we understand the importance of stability and unchanging elements. Constants stand as steadfast pillars, offering values that remain constant throughout your code's journey. Allow us to illuminate the path of constants within Coda.

Declaration of Constants

Much like variables, constants hold a prominent place in Coda's syntax. To declare a constant, you can rely on the const keyword. This serves as a clear indicator that the value you assign is intended to remain unchanged.

const x = 5
const y = "Hello, World!"
const z = true

Consistency with Flexibility

While constants share common attributes with variables, such as types and other properties, they bear a distinctive trait: once defined, a constant cannot be reassigned. This rigidity ensures that the value you set remains a rock-solid foundation for your code's execution.

const x = 5
x = 10  // This will result in an error

The Symphony of Properties

In a harmonious convergence, constants align with variables in their essence. Types, expressions, and all the facets you appreciate about variables are seamlessly woven into the fabric of constants. This consistency simplifies your coding experience and streamlines your understanding of these foundational elements.

A Gentle Reminder

As a friendly reminder, remember that constants are not immune to the allure of types and the captivating dance of expressions. While they remain immutable, their capacity to embody various types ensures your code remains versatile and expressive.