In Scripting, what to put in quotes and what not to put in quotes?

Snehal2
Kilo Guru

Hi Developers,

While scripting, when to use the quotes and when not to use the quotes? Does Single quotes & Double quotes have different meaning? 

Which is right from following?

Eg: current.state=='1'  OR current.state==1

current.u_proposed_as_critical== 'true' OR current.u_proposed_as_critical== true

Thanks in advance,

Snehal

6 REPLIES 6

Saikiran Gudur1
Mega Guru

Hi Snehal,

Thanks for asking a good question in which the new programmers struggle to understand in starting.

1) If you are defining a variable or a argument or an object in a script snippet earlier and you are using them later in script should not use quotes.

Eg1:

var ab = 1;

if you want to print ab value :-

gs.print(ab); //result => 1

gs.print("ab"); / gs.print('ab') //result => ab

 

2) Single quote/double quote will make "string".

eg:

var a = 1;

var b = '1';

now a is a integer & b is a string

if you execute this code you will understand:-

var a =1;

var b ='1';

gs.print(typeOf(a));//integer

gs.print(typeOf(b));//string

 

3) For boolean operators 'true' and true both are valid if you use "==" for comparison.

Eg:-

var a=1;

var b='1';

gs.print(a == b);//true {== it only checks for value}

gs.print(a === b);//false  {this is because === symbol checks for value and type both should match}

 

Thanks,
Saikiran Guduri (NOW)
(Please mark the answer as correct answer/helpful if it helps)

 

 

Hi Saikiran,

Thanks a lot for the reply. This would really be helpful to me.

Can you tell me which one is right from below:

Which is right from following?

Eg: current.state=='1'  OR current.state==1       (its the state value of incident)

current.u_proposed_as_critical== 'true' OR current.u_proposed_as_critical== true (this is from incident)

 

Regards,

Snehal

Hi Snehal,

as you are using "==" (double equal to for comparison) all of them will yield the same result.

All the below are valid for "==":

current.state=='1'  OR current.state==1       (its the state value of incident)

current.u_proposed_as_critical== 'true' OR current.u_proposed_as_critical== true (this is from incident)
If you want to have a typical type check also included then only use "===".
 

Thanks,
Saikiran Guduri (NOW)
(Please mark the answer as correct answer/helpful if it helps)

 

Hi Saikiran,

Thanks a lot for the reply.