Check out a free preview of the full Go for JavaScript Developers course:
The "Empty Interfaces" Lesson is part of the full, Go for JavaScript Developers course featured in this preview video. Here's what you'd learn in this lesson:

Brenna defines what an empty interface is, what type of values it can hold, and explains how the empty interface can be useful.

Get Unlimited Access Now

Transcript from the "Empty Interfaces" Lesson

[00:00:00]
>> So last thing about interfaces I want to cover is this concept of the empty interface. And it's written with the keyword interface and an empty curly braces. And so there are lots of times in your code where you might not be completely sure what's coming in. You don't know if it's a user or a group.

[00:00:15] You don't know what the key value pairs on a map are, but you know, you're accepting some type of map structure. And so an empty interface specify zero methods. It can be used to hold a value of any type. It also can be used by code that expects an unknown type.

[00:00:30] And it allows hold methods and functions on types when you're not totally sure what's expected. So this is kind of like, if you're working with type script or other type specific languages like the any type. You're like, I don't really know what this is, but I know I need to execute this thing on it.

[00:00:42] So you can use the empty interface a little bit more freely. So here's kind of an example. Let's say you have three types that are structs. You've got a user, an admin, a parent, whatever type of struct you're talking about, and you know you're gonna have a people map, but you're not sure what the types are gonna be.

[00:01:01] Maybe new types will be added soon or you're gonna modify the types, you can set a variable that knows it's a map of the key of string and a value of something, I'm not sure what, and then that string key value pair is a little bit more flexible.