User FAQs

If you have a question, please send it to us.

1) 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!" '

2) 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 myLetStr1 = 'text';                   // typeof = string  
let myLetStr2 = String('text'); // typeof = string
let myLetStr3 = new String('text'); // typeof = object

3) Can you convert a 'string' data type to a 'number' data type ?
Yes. There are several ways this can be done.

let myLetStr = 'text';  
let myLetNum;
myLetNum = Number(myLetStr); // explicit
myLetNum = 0 + myLetStr; // implicit

4) Can you convert a 'string' data type to a 'boolean' data type ?

5) 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 myLetStr = 'some'  
console.log( typeof (myLetStr) ); // string
let myLetLength = myLetStr.length;
console.log( myLetLength );
console.log( typeof (myLetStr) ); // string

6) Can you describe the global eval() function ?
This function evaluates a string expression.

let myLetNum1 = 10; 
let myLetNum2 = 20;
let myLetNum3 = eval('myLetNum1 * myLetNum2');

7) 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' 

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext