String JavaScript

In this lesson we will study the JavaScript String function that is used to return a string from a value passed as an argument.

The syntax is as follows: string(object). Where object can be a number value, a Boolean value.

JavaScript string examples

These are some examples:



console.log(String('13years'));
console.log(String('thirteen'));
console.log(String('13:50'));
console.log(String('13-01-20'));
console.log(String('13 01 20'));
console.log(String('true'));
console.log(String('13.50'));
console.log(String('13'));
console.log(String(''));
var num = 10;
console.log(String(num));
var arrayNumeri = [7,12];
console.log(String(arrayNumeri));

Try these simple examples on JavaScript string method, you will always see a string in the browser console, even when we pass a numeric value.

Some useful links

JavaScript tutorial

JavaScript Calculator

Object in JavaScript

For in loop

Caesar cipher decoder

Slot Machine in JavaScript

Introduction to JavaScript language

Learn JavaScript – basic concepts

JavaScript variables and costants

Conditional instruction if, else

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *