Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is the difference between 'type' and 'typeof'?

Asked by 5 years ago

The wiki doesn't really go much into in-depth with the difference, all it says is that 'typeof' is more useful but how?

What is the difference aren't they the same thing?

1
typeof extends type meaning if UserData is found Roblox will try ang get its internal type then fall back to UserData. User#5423 17 — 5y
0
They're the same CallBack methods, ROBLOX is going to deprecate type() soon to replace typeof(), though nothing changed about their functionality. Ziffixture 6913 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Both type and typeof return what sort of data a variable is referring to. An excellent demonstration is given here: https://www.lua.org/pil/2.html

A frustration one might have in Roblox (before typeof came along) was that you couldn't tell the difference between Vector2, Vector3, Instance, etc - type just said they were all userdata. typeof fixes that problem.

ex:

print(type(workspace)) -- userdata
print(typeof(workspace)) -- Instance

print(type(Vector3.new())) -- userdata
print(typeof(Vector3.new())) -- Vector3
Ad

Answer this question