Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 4 Next »

Tables

Operators

Item

Description

+

Addition

Add two variables together to get the result.

Example: 3 + 4 The result will be 7.

-

Subtraction

Subtract one variable from another to get the result.

Example: 7 - 3 The result will be 4.

*

Multiplication

Multiply one variable to another to get the result.

Example: 3 * 4 The result will be 12.

/

Division

Divide one variable from another to get the result.

Example: 7/7 The result will be 1.

%

Modulus

This will grab the remainder from the division of two variables.

Example: 4/3 The result will be 1.

&&

Logical AND

If the two variables being compared are true, it will return true. If one or both are false, it will return false.

Example: If A = true, and B = false

A && B will result in false.

||

Logical OR

If one of the two variables being compared are true, it will return true. If both are false, it will return false.

Example: If A = true, and B = false

A || B will result in true.

!

Logical NOT

Returns the logical inverse of the variable.

Example: If A = true

!A will result in false.

<

Less Than

Will return true if the first variable is less than the second one, and will return false if not.

Example: A = 3, B = 4

A < B will result in true.

>

Greater Than

Will return true if the first variable is greater than the second one, and will return false if not.

Example: A = 3, B = 4

A > B will result in false.

<=

Less than or Equal to

Will return true if the first variable is less than OR equal to the second one, and will return false if not.

Example: A = 4, B = 4

A <= B will result in true.

>=

Greater than or Equal to

Will return true if the first variable is less than OR equal to the second one, and will return false if not.

Example: A = 5, B = 7

A >= B will result in false.

==

Equal to

Will return true if both variables are equal to each other, and will return false if not.

Example: A = 5, B = 5

A == B will result in true.

===

Instance of

Will return true if both variables are equal to each other and are the same type, and will return false if not.

Example: A = 1, B = '1'

A === B will result in false.

!=

Not equal to

Will return true if both variables are not equal to each other, and will return false if not.

Example: A = 2, B = 3

A != B will result in true.

in

In

Will check if the specific property exists within an object.

Example: myObj = {a: 1, b: 2, c: 3};

if ('a' in myObj) {
notification.send('Property "a" exists in myObj.'); // This will be executed
} else {
notification.send('Property "a" does not exist in myObj.');
}

This will result in “Property" “a" exists in myObj being executed.

=

Assignment

Will initialize a value to a variable.

Example: A = 5

A will now equal 5 when called.

+=

Addition Assignment

Adds to the number specified to the variable to its current value.

Example: A = 5;

A+= 2;

A will result in 7.

-=

Subtraction Assignment

Subtracts the number specified to the variable from its current value.

Example: A = 5;

A -= 2;

A will now equal 3.

*=

Multiplication Assignment

Multiplies to the number specified to the variable to its current value.

Example: A = 5;

A *= 2;

A will now equal 10.

/=

Division Assignment

Divides the number specified to the variable by its current value.

Example: A = 5;

A *= 2;

A will now equal 10.

++

Increment Operator

Adds one to the variable.

Example: A = 2;

A++;

A will now equal 3.

--

Decrement Operator

Subtracts one from the variable.

Example: A = 2;

A--;

A will now equal 1.

~

Bitwise invert

Will invert every bit of the variable.

Example: A = 3 (0000 0000 0000 0011)

A = ~A;

A will bits will now be 1111 1111 1111 1100, which is equal to 65532.

&

Bitwise AND

Bitwise logical AND calculation of two variables.

Example: A = 3, B = 4

A & B

This will result in 0.

|

Bitwise OR

Bitwise logical OR calculation of two variables.

Example: A = 3, B = 4

A | B

This will result in 7.

^

Bitwise XOR

Bitwise logical XOR calculation of two variables.

Example: A = 3, B = 4

A ^ B

This will result in 7.

<<

Bitwise Shift Left

Shifts the Bits of the first variable to the left dependant on the bits of the 2nd variable. Fills bits using 0

Example: A = 2, B = 5

A << B

This will result in 64.

>>

Bitwise Shift Right (Signed)

Shifts the Bits of the first variable to the right dependant on the bits of the 2nd variable. Fills bits using a copy of the leftmost bit.

Example: A = 2, B = 5

A >> B

This will result in 0.

>>>

Bitwise Shift Right (Zero Filling)

Shifts the bits of the first variable to the right dependent on the bits of the 2nd variable. Fills bits using 0.

Example: A = 2, B = 5

A >>> B

This will result in 0.

typeof

Will return the data type of the variable.

Example: A = 2;

typeof A;

Will result in a "number".

void

Evaluates a specific instruction but will always return undefined. Used when an expression is used to perform an action without the need for a return instruction.

Example: void function foo() {
notification.send("in foo");
}();

This will have an undefined return value.

new

Used to create a new instance of a user-created object, Date, or Array types.

Example:

var oldTime = new Date("Dec 31 1999");
oldTime.getFullYear(); // 1999
var currentTime = new Date();
currentTime.getFullYear(); // returns the current year

The two dates will create a new instance while displaying their data.

delete

Deletes a property from an object.

Example: This will remove the first name from a resident.

var resident = {
firstName: 'John',
lastName: 'Smith'
};

notification.send(JSON.stringify(resident));
// {"firstName": "John", "lastName": "Doe"}

delete resident.firstName;

notification.send(JSON.stringify(resident));
// {"lastName":"Doe"}

,

Takes both expressions, evaluates them in order, and returns the one on the right. It can be used to take multiple actions during a for loop.

Example:

var s = "";
for (var i = 1, j = -1; i <= 3; i++, j--) {
s += "i: " + String(i) + ", ";
s += "j: " + String(j);
s += "\n";
}
notification.send(s);
// i: 1, j: -1
// i: 2, j: -2
// i: 3, j: -3

?…:

Checks if a statement is false. In the format of a ? b : c ,It will check if a is true or not; if true, return b, if false, return c. Similar to an if…else statement.

Example:

var isOn = tag.read("checkLight");
var s = isOn ? "Light is on.": "Light is off.";
notification.send(s);

Keywords

Item

Description

ifelse

The if statement executes instructions if the condition is true. Otherwise, it will run the else statement to run a different set of instructions else if can be used to specify a different set of instructions with different conditions.

while

Will repeatedly execute while the condition is true. It will stop once it becomes false.

dowhile

Will allow you execute with the contents of a while loop once before the condition is evaluated. While the condition is true, it will keep executing until it becomes false, exactly like a normal while loop.

for

A for loop will repeat a set number of times until the specified condition becomes false.

break

Terminates a while loop, for loop, or switch statement completely. This will prevent execution of any following cases or loops.

continue

Terminates the running of the current iteration in a loop, then runs the next one.

switchcase

Allows users to compare an input value to the value of each case. If the case matches, it will run the code for that case. If no cases match, a default case will be run.

default

The code that will run if no cases are matched in a switch statement.

function

Block of code that is designed to perform a specific action or task

return

Ends the function execution and will return the specified value.

arguments

Can be used within a function to get values passed into the function.

trycatch

Allows users to execute a block of code that might not run successfully; if it does fail, a catch block will be able to handle it in the event of a failure.

throw

Throws an error object, ending the script with a popup error. It can be used within a try block to be tested without interfering with the rest of the project.

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.