Hey Coders!! π©βπ»
So, This is the Part-3 of Javascript for Beginners!!π
And in Part-1 we had learned about Printing Statements, Variables in JS and Arithmetic Operators. Remember??
And in Part-2 we had learned about Incrementing numbers, Decrementing numbers, Shortcuts :(*=, /=), Add 1 to number, Escape sequences in stringsπ
If you have not seen my Part-1 and Part-2 go watch now because in that 2 articles we have talked about the basic things in JS!π
Topic:π
Concatenating strings with plus operator π
EXAMPLE:
var myStr = "Hi I am amena," + " How are you?"
console.log(myStr)
OUTPUT:
Concatenating strings with plus equals operatorπ©
- We can also get an output with the plus equals operator.
EXAMPLE:
var bat = "This is my bat "
bat += "and this is my ball"
console.log(bat)
OUTPUT:
Constructing strings with variablesπ
var firstCode = " my first coding language was Python."
var askingYou = "Hi my name is Amena," + firstCode + " What was yours?"
console.log(askingYou)
OUTPUT:
Activity!!π©βπ»
So the activity for you is you need to output: Twitter is awesome But with a twist! I want you code with me!!π
Step 1: Make a variable name it
myStr
, inside this writeawesome!
.Step 2: Make another variable name it
ourStr
inside this writeTwitter is
Step 3: Now, I want an output as
Twitter is awesome!
but you must use+=
operator!
BEST OF LUCK!π
Find Length of stringπ
Sometimes you wanna find the length of strings, Javascript makes it easier!!
To find the length of the string JS has the special operator called .length
EXAMPLE:
var code = "Coding is fun"
console.log(code.length)
OUTPUT:
13
- Here we're getting
13
because it counts thespaces
also and also it starts with0
like0, 1, 2, 3.....
Bracket Notations to find the characters of stringsπ²
OUTPUT:
N
Bracket Notations to find the last letter!π
If you'll just write -1
after the strings then you must get the last letter of the string ππ
Similarly if you write
-2then you'll get the second last letter of the string.
Hopefully you are done with the length part!!π
So, now there is a deal, that you need to write this all and try to understand because, if you just see it you cannot learn it. Hopefully you'll do it!!β€
Motivation for today: Talk is cheap, Show me the codeπ¨βπ»
If you guys found this article useful comment πππ!!
So, this was my Javascript for beginners Part-3. Now, I will see you all again tomorrow in my Part-4 till then byee!!π