Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js String

"Hello World"
'Hello World'
"Hello " World"
"Hello  World"
"Hello n World"
'Hello ' World'
'Hello t World'

//Concatenation
"Hello" + "World"


var x = "Hello World";

//Length of String
x.length; //It is a property

//Indexing
"Hello World"[0]
"Hello World"[3]
x = "Hello World";
x[0]
x[3]

//Immutable
x[1]
x[1] = "5"
x[1]


// return a new string, doesn't change x
//These are methods
x.slice(1, 5);
x.slice(-6, -1);
x.substr(3, 2); // 2nd parameter means the length
x.replace("Hello", "World");
x.toUpperCase();
x.toLowerCase();
x.concat("1", "2");
x.trim();


//links
//https://www.w3schools.com/jsref/jsref_obj_string.asp
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
Comment

Create JavaScript Strings

//strings example
const name = 'Peter';
const name1 = "Jack";
const result = `The names are ${name} and ${name1}`;
Comment

JavaScript String() Function

const a = 225; // number
const b = true; // boolean

//converting to string
const result1 = String(a);
const result2 = String(b);

console.log(result1); // "225"
console.log(result2); // "true"
Comment

JavaScript String

//strings example
const name = 'ram';
const name1 = "hari";
const result = `The names are ${name} and ${name1}`;
Comment

Javascript string


'I'.repeat(3)

 // III
Comment

string js

const string1 = "A string primitive";
const string2 = 'Also a string primitive';
const string3 = `Yet another string primitive`;
const string4 = new String("A String object");
Comment

string in js

let str1 = 'hello'
let str2 = 'hello'
let strObj1 = new String('hello');
let strObj2 = new String('hello');

console.log(str1 === str2) // true

console.log(str1 == strObj1) // true
console.log(str1 === strObj1) // false

console.log(strObj1 == strObj2) // false
Comment

Javascript Strings

// JavaScript String
const data =
{
    "name": "John Doe",
    "age": 45
}
function Sample() { return "TEXT"; }

var str1 = 'With " in it "';
var str2 = "With ' in it '";
var str3 = `Contains other Strings >${str1}<, Properties of objects >${data.age}< or return values from functions >${Sample()}<.`;

console.log(str1); // With " in it "
console.log(str2); // With ' in it '
console.log(str3); // Contains other Strings >With " in it "<, Properties of objects >45< or return values from functions >TEXT<.
Comment

js string

var myString = "foobar";
//Can use single quotes, double quotes, or backticks for template literals.
Comment

PREVIOUS NEXT
Code Example
Javascript :: pm2 change log timestamp 
Javascript :: react setstate synchronous 
Javascript :: regex or operator 
Javascript :: how to change port in next js 
Javascript :: comments in jsx 
Javascript :: req.header express.js 
Javascript :: resolvers in angular 
Javascript :: destructuring an array 
Javascript :: bot react message with custom emoji 
Javascript :: jquery OR operation 
Javascript :: jquery get element attribute 
Javascript :: joi.validate 
Javascript :: props history 
Javascript :: add to json object javascript 
Javascript :: vue create component 
Javascript :: string literals 
Javascript :: return data with ajax 
Javascript :: jq cheat sheet 
Javascript :: background image react 
Javascript :: javascript prototype inheritance 
Javascript :: js for loop 
Javascript :: string en javascript 
Javascript :: Drop it 
Javascript :: typeahead bootstrap 4 add multiple values 
Javascript :: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms 
Javascript :: show mwssage js 
Javascript :: i need to keep track of quantity in inventory using JavaScript backend 
Javascript :: @angular/fire has missing dependencies 
Javascript :: jquery unobtrusive validation asp.net core 
Javascript :: org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONObject 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =