In the first part we have learned about :Printing Statements, Variables in JS and Arithmetic Operators!!
Hopefully that went well!
- 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")
- I am a string
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)
var a = 10 var b = 20 var c = 30 console.log(a *= 10) console.log(b *= 10) console.log(c *= 10)
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 console.log(coding)
This one is not wrong!
BUT, BUT, BUT we have a more easy way. LIKE THIS👇
var coding = 100 coding++ console.log(coding)
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!)
Escape sequences in strings🎃
Now I'll give some examples related to these
CODE OUTPUTS 👆 :
- So, If you want an output with the
single quotethen 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 quotesthen 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
backslashyou can use
\\. if you want an output like this :-
cookie\then you can use
- Similarly, if you want an output with a
new lineyou must use
var cookie = "cookies\nare the best!!" console.log(cookie)
- Now, we'll talk about
\rin 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.
console.log("Hello coders!") console.log("Hello \rcoders!")
- Now, if you want an output with the
tabso you can do
var cookie = "cookies \t are the best!!" console.log(cookie)
- Now, we'll talk about the
var cookie = "cookies\b\b\b are the best!!" console.log(cookie)
Hopefully that went well!!😀
- Now you'll be having a homework of
form feed(ON YOUR OWN) All the best!!
Motivation for today: Any fool can write code that a computer can understand...😉