Composing variable value from other vars

I want to do something like this. What is the correct syntax?

variable "location" {
  description = "Location of the project in Azure"
  default     = "cc"

variable "env" {
  description = "infrastructure environment"
  default     = "z"

variable "prefix" {
  description = "Prefix for objects"
  default        = "${var.env}-${var.location}"

You can’t compose a variable from another variable, but there is another type of variable called local that allows this.

# define prefix
locals {
  prefix = "${var.env}-${var.location}"

# use prefix
resource "..." "..." {
  name = local.prefix

But can the locally defined parts be used outside of the scope of that file?

Yes anywhere within the scope of Terraform module / directory.