Assigning text to a varaible

Hello everyone! I want to make a game where there is an object and a variable that depends the object’s material. The number is stored in an object’s Text component. Now I have a JavaScript in which I have a variable which must get the value of the text. How do I do that

If your script is attached to the object, then you can use Text t = GetComponent() (in C# syntax, sorry), and then read out t.text

Thanks, but I found my problem. I forgot to add the using UnityEngine.UI at the top. Thanks anyway!