This scenario is the preoperational stage of cognitive development. The stage mainly affects children around eight months of age. During this stage, the ay has developed the ability to visualize things that are not physically present. This crucial to the acquisition of object permanence is the most fundamental achievement of the whole sensorimotor stage of development.
They have object permanence because they can form a mental representation of the object in their minds and when the object is taken from them they will tend to look for it.