Press ESC to close

JavaScript string

0 1336

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

Other stories

JavaScript eval

Next Story

JavaScript parseFloat

Previous Story