OfficeScripts Type Variables set and assign value

Here’s a sample OfficeScript that demonstrates various types of variables and how to assign data to them:

function sampleVariableAssignments() {
  // String variable
  var name = "John Doe";
  
  // Number variable
  var age = 30;
  
  // Boolean variable
  var isActive = true;
  
  // Array variable
  var fruits = ["Apple", "Banana", "Orange"];
  
  // Object variable
  var person = {
    firstName: "John",
    lastName: "Doe",
    age: 30
  };
  
  // Date variable
  var currentDate = new Date();
  
  // Null variable
  var nullValue = null;
  
  // Undefined variable
  var undefinedValue;
  
  // Assigning data to variables
  name = "Jane Smith";
  age = 35;
  isActive = false;
  fruits.push("Mango");
  person.age = 40;
  
  // Logging variable values
  console.log("Name: " + name);
  console.log("Age: " + age);
  console.log("isActive: " + isActive);
  console.log("Fruits: " + fruits.join(", "));
  console.log("Person: " + JSON.stringify(person));
  console.log("Current Date: " + currentDate);
  console.log("Null Value: " + nullValue);
  console.log("Undefined Value: " + undefinedValue);
}

In this sample code, we have declared variables of different types:

  • name is a string variable assigned with a name.
  • age is a number variable assigned with an age.
  • isActive is a boolean variable assigned with a true/false value.
  • fruits is an array variable assigned with a list of fruits.
  • person is an object variable assigned with properties of a person.
  • currentDate is a date variable assigned with the current date.
  • nullValue is a variable assigned with a null value.
  • undefinedValue is a variable assigned without any value, resulting in an undefined value.

The code then demonstrates how to assign new values to these variables using simple assignment statements. Finally, the values of these variables are logged to the console.

You can execute the sampleVariableAssignments function to see the assigned values and their corresponding types in the console output.

Please note that OfficeScripts are only supported in Excel for the web and Excel Online, and they may have limitations compared to other programming environments.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech