how to create a variable code example

Example 1: js variable

var Number = 5;
var String = "Hi!";
var boolen1 = true;
var boolen2 = false;
var array = [11, "Hi!", true];
var object = {age:11, speach:"Hi!", likes_Bananas:true};

Example 2: how to declare a variable js

//let and var are both editable variables and can be changed later on in your program;
let dog = 'Woof';
//dog is equal to the string 'Woof';
dog = false;
//You can changed the value of dog now because it was defined with let and not const;

let cow = 'Moo';
//cow is equal to the string 'Moo';
cow = true;
//You can change the value of cow later on because it is not defined with const;

//const is used when declaring a variable that can't be changed later on -- const stands for constant;
const pig = 'oink';
//This assigns the string 'oink' to pig which can not be changed because it is defined with const;
pig = 'snort';
//Above throws an error
//Good Job you now know how to declare variables using JavaScript!!!

Example 3: how to make variable

local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local DefaultSize = script.Parent.Size

function determineClosest(EggsAvailable)
	local CurrentClosest = nil
	local ClosestDistance = script.Parent.MaxMagnitude.Value
	for i,v in pairs(EggsAvailable) do
		local Egg = workspace.Eggs:FindFirstChild(v)
		local mag = (Egg.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
		if mag <= ClosestDistance then
			CurrentClosest = Egg
			ClosestDistance = mag
		end
	end
	return CurrentClosest
end

RS.RenderStepped:Connect(function()
	if Player.Character:FindFirstChild("Humanoid") then
		if Player.Character.Humanoid.Health ~= 0 then
			local EggsAvailable = {}
			local CameraRatio = ((Camera.CFrame.Position - Camera.Focus.Position).Magnitude)/11
			script.Parent.Visible = false
			for i,v in pairs(game.Workspace.Eggs:GetChildren()) do
				local mag = (v.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
				if mag <= script.Parent.MaxMagnitude.Value then
					EggsAvailable[#EggsAvailable+1] = v.Name
				end
			end
			if #EggsAvailable == 1 then
				local Egg = workspace.Eggs:FindFirstChild(EggsAvailable[1])
				local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
				script.Parent.Visible = true
				script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
				script.Parent.CurrentTarget.Value = Egg.Name
			elseif #EggsAvailable > 1 then
				local Egg = determineClosest(EggsAvailable)
				local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
				script.Parent.Visible = true
				script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
				script.Parent.CurrentTarget.Value = Egg.Name
			elseif #EggsAvailable == 0 then
				script.Parent.CurrentTarget.Value = "None"
			end
			script.Parent.Size = UDim2.new(DefaultSize.X.Scale/CameraRatio, DefaultSize.X.Offset, DefaultSize.Y.Scale/CameraRatio, DefaultSize.Y.Offset)
		end
	end
end)

Tags: