Blog 2: An Overview of Key JavaScript Ideas

Blog 2: An Overview of Key JavaScript Ideas

Hey there,

coding buddies! 😄

Coders!!🤎 Get ready for a thrill ride! 🚀 In the first part, we discovered the magic of printing statements, explored the incredible world of variables in JavaScript, and mastered the art of arithmetic operators! 💥 Let's keep the fun going! 🎉

Hey Coders! 🤎 Welcome to Part-2 of our friendly Javascript for Beginners series! If you haven't had a chance to check out Part-1 yet, please do - we covered some really cool basics like printing statements, variables, and arithmetic operators in JavaScript. Enjoy! 😊

Topic👇

Incrementing Numbers 🦀

image_name

Now can we make this more easy?? We can use the+= it's the short and easy way to add something!! LIKE THIS👇

var a = 10
var b = 20 
var c = "I am a"

console.log(a += 10)
console.log(b += 10)
console.log(c += " string")

Output:

  • 20

  • 30

  • I am a string

Decrementing Numbers🧩

To do decrement numbers you can use (-=) LIKE THIS👇

var a = 10 

var b = 20 

var c = 30 

console.log(a -= 10) 

console.log(b -= 10)

console.log(c -= 10)

Output:

  • 0

  • 10

  • 20

Shortcuts :(*=, /=)💡

var a = 10

var b = 20

var c = 30 

console.log(a *= 10) 

console.log(b *= 10) 

console.log(c *= 10)

Output:

  • 100

  • 200

  • 300

NOW TRY TO DO / ON YOUR OWN

Add 1 to number👑

Now what if you wanna add 1 to the number? OfCourse you guys will do: LIKE THIS 👇

var coding= 100
coding= coding+ 1

Output:

  • 101

This one is not wrong!

BUT, BUT, BUT we have a more easy way. LIKE THIS👇

var coding = 100 
coding++ 
console.log(coding)

Output:

  • 101

**Here, we have done it by ++ because in JS we'll find such interesting and easy ways!**

Similarly you can do this method with (--) also!! (Try on your own!)

FUNFACT: After doing Javascript we think that we are actually doing coding!!😎

Escape sequences in strings🎃

Code Snippet

Now I'll give some examples related to these CODE OUTPUTS 👆 :

  • So, If you want an output with the single quote then you can use \'. Means if you want an output like this :- cookie' then you must use \' !!

  • And if you want to have a output with the Double quotes then you can use \". if you want an output like this :- cookie" then you must use: \" As shown in figure!!

  • Also if you an output with a backslash you can use \. if you want an output like this :- cookie\ then you can use \.

  • Similarly, if you want an output with a new line you must use \n. EXAMPLE:

var cookie = "cookies\nare the best!!"

OUTPUT :

Code Snippet

Now, we'll talk about \r in JS it's the carriage return. A carriage return is a type of escape character that will reset the position of the cursor to the beginning of a line of text.

EXAMPLE:

console.log("Hello coders!")
console.log("Hello \rcoders!")

OUTPUT:

Code Snippet

Now, if you want an output with the tab so you can do \t.

EXAMPLE:

var cookie = "cookies \t are the best!!"

OUTPUT:

Code Snippet

Now, we'll talk about the backspace in JS.

EXAMPLE:

var cookie = "cookies\b\b\b are the best!!"

OUTPUT:

Code Snippet

Hopefully that went well!!😀

Now you'll be having a homework of form feed (ON YOUR OWN) All the best!!

Try on your own

Today's inspiration: It takes a thoughtful mind to create code that is easily understood by both computers and fellow developers. 😉

If you found this article helpful, leave a comment with a 👑👑. So, this was my uplifting Javascript for beginners Part-2. Now, I'm excited to see you all again tomorrow in my Part-3. Until then, take care and stay positive!! 💙