User FAQs - Strings
If you have a question, please send it to us.
1) Should strings be enclosed in single or double quotes ?
Both single (' ') and double (" ") quotes can be used to represent a string in Javascript.
There is no concept of a character, everything is a string.
let myText1 = "some ' text"
let myText2 = 'some " text'
When it is just a text string or constant, use double quotes.
myObject.load("items/name");
When there is any string concatenation, use single quotes.
let myText = '=JS.' + _fName + '(' + _arguments1 + ',FALSE)'
2) Can you describe the string data type ?
A string is a collection of characters.
It can be enclosed in single or double quotes.
You can use the plus sign to represent string concatenation
Some other common escape sequences are \t to embed a tab and \n to embed a new line.
You can also use \uHHHH where HHHH is a 4-digit hexadecimal code to embed a unicode string.
Special characters are single quote, double quote, apostrophe and ampersand.
'The quick brown fox jumps over the lazy dog'
'The doctor said "Today is your lucky day!" '
'The doctor said "I\'m pleased to announce that it\'s a girl!" '
3) How many different ways can you concatenate two strings ?
You can use the + (unary) operator.
const myText = 'Better' + ' ' + 'Solutions';
You can use the String concat method.
const myText1 = 'Better';
const myText2 = myText1.concat(' ', 'Solutions');
You can even use the Array join function.
['Better', ' ', 'Solutions'].join(''); // 'Better Solutions'
4) Can you explain the unary operator (+) ?
This operator depends on the data type of the operands.
If all the operands are numbers, it will perform addition.
If any of the operands are not numbers or boolean, it will perform string concatenation.
console.log( true + 1 ); // 2
console.log( false + 1 ); // 1
5) Can you explain the difference between the global String() function and the String constructor ?
The String() function can be used with primitive/literal values or with objects.
When used with literal values this function can be used to convert literal values to a 'string' data type.
When used with the 'new' keyword this function can be used as a constructor to create a String object.
let myText1 = 'text'; // typeof = string
let myText2 = String('text'); // typeof = string
let myText3 = new String('text'); // typeof = object
6) Can you convert a 'string' data type to a 'number' data type ?
Yes. There are several ways this can be done.
let myText = 'text';
let myNum;
myNum = Number(myText); // explicit
myNum = 0 + myText; // implicit
7) What is displayed in the Console ?
console.log(5+"5"); // 55 - implicity converted to string
console.log("5"+5); // 55 - implicity converted to string
console.log(5+5); // 10 - both operands are numbers
console.log(5-"5"); // 0 - implicitly converted to number
console.log(5-"5*"); // NaN - second argument cannot be converted to number
console.log(5*"5"); // 25 - implicitly converted to number
console.log(5/"5"); // 1 - implicitly converted to number
console.log( String(null) ); // ?
console.log( String(undefined) ); // ?
console.log( String(true) ); // ?
console.log( String(false) ); // ?
8) Can you convert a 'string' data type to a 'boolean' data type ?
const myText = 'Better';
console.log( myText === 'true'); // true
var isTrueSet = (String(myText).toLowerCase() === 'true');
if (String(a).toLowerCase() == "true")
9) Can you explain why you can access properties off a string value data type ?
JavaScript will automatically convert value data types (number, string, boolean) to their object equivalent data types temporarily if it detects a property has been appended to a value data type.
let myText = 'some'
console.log( typeof (myText) ); // string
let myNum = myText.length;
console.log( myNum );
console.log( typeof (myText) ); // string
10) Can you describe the global eval() function ?
This function evaluates a string expression.
let myNum1 = 10;
let myNum2 = 20;
let myNum3 = eval('myNum1 * myNum2');
11) What are Escape Characters ?
These can be used when working with special characters like single quote, double quote, apostrophe and ampersand
console.log("some \" text"); // 'some " text'
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext