This is due to the risk of food or liquids coming back up from the stomach which can lead to very serious problems in the airways and lungs. Always therefore be honest when saying how long it has been since you child last ate or drank, even if this would mean you might have to wait or that the operation needs to be performed later.
Fluids need a shorter nil by mouth time than solid food. Different drinks need different nil by mouth times, however. Juice and yoghurt drinks need longer to pass through than water, carbonated soft drinks and coffee, for example. Breast milk and formula milk are a cross between liquid and solid food.
Contact the hospital if anything in the nil by mouth instructions you have been given is not clear.