-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable_string.js
44 lines (34 loc) · 1.02 KB
/
variable_string.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var s1 = 'hello';
// escape character, backslash will join the text
// var myStr = "I am a "double quoted" string inside "double quoted"";
var myStr = "I am a \"double quoted\" string inside \"double quoted\"";
console.log(myStr)
var myStr2 = 'I am a "double quoted" string inside a single quoted';
console.log(myStr2)
/*
CODE OUTPUT
------------------
\' single quoted
\" double quoted
\\ backslash
\n new line
\t tab
*/
console.log("First line text\n\tSecond Line\nThird line \\")
var s2 = 'buddy';
console.log(s1 + " " + s2)
s1 += s2
console.log(s1)
// string with variables
var greetingMessage = 'hello ' + s2;
console.log(greetingMessage)
// find a length of the string, it does not include whitespace
greetingLength = greetingMessage.length;
console.log(greetingLength)
// bracket to find substring
console.log(greetingMessage[0])
// Strings are immutable,
var immutableStr = 'Jello world!';
console.log(immutableStr)
immutableStr[0] = 'H' // we can't change part of the string due to immutability
console.log(immutableStr)