logoJourney BlogAffiliate links are used in this blog to earn income
WrappedUsername

WrappedUsername

Aug 04, 2022

Basic JavaScript Notes

Basic JavaScript Notes

Compound assignments += -= *= /=

/// @notice augmented addition const myVariable += 2; /// @notice augmented subtraction const myVariable -= 2; /// @notice augmented multiplication const myVariable *= 2; /// @notice augmented division const myVariable /= 2;

Escaping literal quotes \ before "

const myVariable = 'backslash before, let\'s use "quotation marks" inside a string.';

Single quotation marks ' vs. double "

/** @notice When using both single and double quotation marks inside a string one must use the proper escape sequence, because if you have that same quotation mark somewhere in the middle, the string will stop early and throw an error. */ const myVariable = 'backslash before, let\'s use "quotation marks" inside a string.'; /// @notice The use of single quotation marks allows the proper use of double quotation marks inside the string. const myVariable = '<a href="http://www.example.com" target="_blank">Link</a>';

Escape sequences

CommandDescription
\'Single Quotation Mark
\"Double Quotation Mark
\\Backslash
\nNew Line
\rCarriage Return
\tTab
\bWord Boundry
\fForm Feed
const myString = "FirstLine\n\t\\SecondLine\nThirdLine"; console.log(myString); /** @notice output: FirstLine \SecondLine ThirdLine */

Concatenating strings.

/** @notice Use the += operator to concatenate a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines. */ /// @notice Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. let myVariable = "This is the first sentence. "; myVariable += "This is the second sentence.";

Constructing strings with variables.

/** @notice By using the concatenation operator + you can insert one or more variables into a string you're building. */ const myName = "WrappedUsername"; let myVariable = "Hellos my name is " + myName + ", how are you?";

Appending variables to strings.

/// @notice Appending variables to a string using the plus equals += operator. const someAdjective = "interesting!"; let myVariable = "Learning to code is "; myVariable += someAdjective;

Find the length of a string.

/// @notice Find the length of a String value by writing .length after the string variable or string literal. let myNameLength = 0; const myName = "WrappedUsername"; console.log(myName.length); myNameLength = myName.length;

In Conclusion

  • Are you currently looking for a web3 blockchain job or other dev jobs? Check this out! Developer Jobs Here!
WrappedUsername

WrappedUsername

I am a self taught Solidity Smart Contract Auditor. Creator of this blog site.

Leave a Reply

Related Posts

background image

🎉 Thank you! 🎉

Our sponsor Foam Chunk Smudge NFT, an abstract art project, has created a token pass utility for this NFT. The Foam Chunk Smudge NFT token HODLer community on Discord has access to private channels with special vip only announcements, and much more! Check them out!

Our Sponsor

Categories

logoJourney Blog

© 2023 Journey Blog. All rights reserved.