Hello, fellow coders! Welcome back to the latest installment of "Priyanshu Mishra Blogs"!
Today, we're diving into Part-3 of our JavaScript for Beginners series, and I can't wait to see your programming skills continue to grow. ๐
Just to jog your memory, in Part-1, we delved into the world of JavaScript with topics like Printing Statements, Variables, and Arithmetic Operators. It was a foundational step that set the stage for your coding journey.
And who can forget Part-2? We explored Incrementing and Decrementing numbers, handy Shortcuts (*=, /=), adding 1 to numbers, and even cracked the code on Escape sequences in strings (๐).
If you haven't had the chance to check out Part-1 and Part-2, I highly recommend doing so. These articles lay the groundwork for what we're about to explore in this edition. ๐
Now, let's get ready to level up your JavaScript skills! ๐ป๐ฅ
Topic:๐
Concatenating strings with plus operator ๐
EXAMPLE:
var mystr = "Hi I am Rachit, " + " 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 C++."
var askingYou = "Hi my name is rachit," + firstCode + " What was yours?"
console.log(askingYou)
OUTPUT:
Activity Time!!!
Let's add a twist to our coding adventure! ๐
Step 1: We'll kick things off by creating a variable called myStr
and filling it with the word "awesome". Here's how you do it:
javascriptCopy codelet myStr = "awesome";
Step 2: Next, we're crafting another variable called ourStr
and this time we're infusing it with "blog is". Here's your line of code:
javascriptCopy codelet ourStr = "blog is";
Step 3: Now, the exciting part! We want to combine these two strings to produce our output: "blog is awesome!" using the +=
operator. Let's make the magic happen:
javascriptCopy codeourStr += " " + myStr + "!";
And there you have it, folks! We've successfully constructed the phrase "blog is awesome!" with a bit of JavaScript code. Your coding skills are on fire! ๐ฅ๐ป๐
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" //space is also counted as a lenth
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!!๐
You've got this! Learning by doing is the key to mastering coding. ๐ชโค๏ธ
Inspiration for Today: Just remember, every great coder once started as a beginner. So, let's get our hands dirty with some code! ๐จโ๐ป
I genuinely hope you all found this article not just useful, but downright awesome! ๐๐๐ If it helped you, please don't hesitate to drop a comment and share your thoughts. Your feedback keeps me motivated and inspired!
So, that's a wrap for Part-3 of our JavaScript for Beginners series. I'll be right back here tomorrow with even more exciting stuff in Part-4. Until then, take care and see you soon! ๐