JavaScript for Beginners #9 - String Methods and Manipulation

Tech With Tim · Beginner ·🧠 Large Language Models ·6y ago

Key Takeaways

This video tutorial covers JavaScript string methods and manipulation for beginners, demonstrating various methods such as toUpperCase(), toLowerCase(), startsWith(), and endsWith() to parse and clean user input. The tutorial uses JavaScript as the primary tool and focuses on string manipulation and input validation concepts.

Full Transcript

hello everybody and welcome back so in this video we are we talking about string methods and concatenation of strings now we've dealt with strings a little bit before I've showed you as a few things we can do with them but I just want to show you a few other properties of strings because there is actually a lot and there's a lot of things that you kind of need to learn to deal with them properly and that's also something you're gonna be doing a lot in JavaScript is manipulating strings and user input and all of that so what I want to do is kind of have an example here where we're gonna get the user to type something and we're gonna modify the string they type in and just print it and show you what it looks like so to do this we're gonna say you know I probably should have kept this from the last time var text equals in this case I guess we'll say document dot get element by ID don't what was it valium I think it was value okay let's change this now to be a mp4 input and what I'm gonna do is simply just console dot log or actually we'll put that value in this output tag so what we'll say is output dot inner HTML equals and in this case text now let's just look at this example quickly to see how this works I'm also going to talk about this page in a second so let's refresh this let's type hello and then we can see obviously it shows up down below now this is where I'm grabbing some of these string methods from this just has a nice list of them I'll try to leave a link to it but remind me if I forget which is likely so those methods like starts with substring substring to local lowercase to string to lowercase to uppercase trim I'm not going to go through all of them but I'll show you what some of them do and why we might even actually want to use them so the easiest one to illustrate is to uppercase now you guys can probably guess what this is gonna do but essentially whenever you have a string object which in this case text is because this right here is gonna be storing some string value right this is going to be equal to a string so text now is storing some string which means that I can actually manipulate the variable text by calling you know some string methods on it so let's do this and let's refresh so when I do that and I type let's say hello we can see we get hello now in all upper cases so what to uppercase does is essentially take this string and create a new string is completely uppercase letters with whatever this string was now if I decide to add you know an uppercase o at the end we still are gonna get this because everything just goes uppercase now the same works for two lowercase like that so let's look at this so I go to lowercase and I type low then we're gonna get lowercase hello so this is often useful especially when you're asking maybe a question or something that could be right or wrong because you don't know if someone's gonna type in the answer with upper cases or with lower cases or maybe you know say they're gonna type in the answer to a question like maybe the answer is blue and they type blue with a capital B well is that wrong if B your answer that you had was blue with a lowercase B no the answer is still correct but if you're comparing you know blue like this with let's say something like blue obviously you know these two are not the same so what you would do is take that users input make it all lowercase so then that way you can compare if the value of your two strings are actually the same so that's where we use to lower case and dot uppercase now what we can actually do is starts with and ends with as well and this is gonna give us a boolean so starts with is gonna tell us if the string starts with a certain character so what we need to do is inside of here put the character we want to see if it starts with now maybe we want our string to start with a number sign or maybe we wanted to start with an @ sign like if we're doing a mention of someone on social media or something so what I can do is refresh this and now if I type say hello we're gonna get the value false but if I type at hello like this we get the value true because our string started with this character now same goes with ends with we have ends with we can use that same character again so in this case we'll do hello false hello with one of those at the end and what do we why are we not getting correct here let's see if this works hello hmm interesting why we keep getting false let me look at this okay so we got true there I think I actually had a space afterwards and that's why I wasn't working and that's actually the next one I'm going to talk about so notice here we're getting true but if I had a space then we get false so I think that's what was happening was essentially this string has a space at the end so that's why that was working so actually what I want to show you now is how can we get rid of that space so in that last instance right our string actually did end with this add sign but since we had a space at the end it wasn't counting because it was gonna look like something like I think we had like hell at like that so this was our string so obviously we see it ends with this but there is a space so how can we get rid of any of those spaces at the end or at the beginning of that string that we don't want well this is where we can actually use a method called trim now what trim is gonna do is simply remove any leading or trailing white spaces from our string so this is really useful because sometimes maybe someone's typing in their name or something and they type in like space hello well you don't want to store space hello you just want to store hello so in this case actually let's refresh this and if I do hello and like a bunch of spaces we're good okay so we're obviously gonna get false because there's a bunch of spaces but let's do this same example zoom hello at and then a bunch of spaces and click well our answer is true because we actually removed all these spaces when we did this trim here so that's what that does it actually removes any spaces I think a better example might be if we just actually print out text trim and I'll do some leading spaces so if I go like hello and just do a bunch of spaces here then technically when we printed this it should be expand we run this we just oh well I got to refresh this let's go hello do this we just get hello there's no spaces before that because we trimmed off all of those spaces so that's what those methods do now notice that I used two of those in combination with each other right so I had dot trim which returns to me a new string so that's gonna give me that hello without all those spaces there so it removes all those and then what I did was dot ends with like that right so what these methods do is they don't modify the original string they actually create a new one that can be used in whatever context you want right so if I have this you know let's do this trim what I'll do next is all this console dot log the actual value of text and show you guys the text isn't changing when we do this dot trim this just creates a new string they get stored in our inner dot HTML output it doesn't actually modify text so to illustrate that let's refresh this to do a bunch of spaces for hello click we can see that change but now if I go to inspect and we look at the console here which I think is right here we can see that we get hello and we actually have a bunch of spaces before that now I realize that sometimes it's hard to see the actual spaces so I'm gonna show you another property we have strings called lengths now what this does is it's different than a method which are what these are that we've been calling with these dot and then these brackets it actually tells you how long the string is which is kind of useful so in this case let's refresh this let's go a bunch of spaces hello click and in this case obviously we know that the string is only of length I believe 6 but here we're getting length 23 and that's because we've added a bunch of the spaces beforehand so it's printing out that length to us now this length property is really useful because sometimes like say you have a password you want to check well that password has to be of length at least 250 or something like that right or you know 250 25 10 whatever you want it to be like you need to have it of some certain length so what you do is you could check the length of whatever that user typed in say okay is it greater than H is it greater than 9 does it contain an add sign does it start with a capital whatever any of those you can check all that and if that's true you could say okay this is a valid password you can say okay no that's not a valid password so as that is a little bit about strings I mean I think I've showed you guys concatenation before where essentially we've had something like you know hello plus and then maybe in this case if we do text actually let's do this what I'm gonna do is simply say ask the user to type in their name now so we'll say to actually type something sure and we'll say you typed like that and then space now I think I showed you guys how this worked but essentially concatenation with strings is just adding them together so what we're gonna do here is that you typed and then just add this text trimmed value after so in this case if i refresh this we can close this console window actually let's get out of that and I type hello it'll say you typed hello right and that'll just print that out and show that to me now let's say I wanted to actually you know maybe print some numbers I want to print some other things well what I can do is I don't need to put them in strings I can say like plus five if I wanted to and I think I showed you guys how this works will essentially in now if I type hello it's just gonna add five to the end so just mush that together alright so I think that's all four strings for right now there is a lot more to talk about with strings again try to remind me to link this website that has a bunch of different methods that you can use for Strings I haven't shown all of them or even like most of them to be honest like there's a replace method which will replace a certain item in the string with another item we have split which will split this string we'll talk about that one later just lots of stuff you can do here I just want to give you as an introduction and illustrate kind of how these work and how you can use the methods and you know how I did something like text trim even though text isn't actually string but it's storing the string value stuff like that so anyways if you guys enjoy it as always leave a like subscribe to the channel down below and I'll see you guys another JavaScript tutorial

Original Description

In this javascript tutorial for beginners I will be discussing string methods and manipulation. I will show some popular string methods like .toUpperCase, .trim() , .startsWith() and many others. This will help you learn how to parse and clean user input! Playlist: https://www.youtube.com/watch?v=ykoxwrm0Seo&list=PLzMcBGfZo4-njtc5xy3qli4cN2zlKsoxd ◾◾◾◾◾ 💻 Enroll in The Fundamentals of Programming w/ Python https://tech-with-tim.teachable.com/p... 📸 Instagram: https://www.instagram.com/tech_with_tim 🌎 Website https://techwithtim.net 📱 Twitter: https://twitter.com/TechWithTimm ⭐ Discord: https://discord.gg/pr2k55t 📝 LinkedIn: https://www.linkedin.com/in/tim-rusci... 📂 GitHub: https://github.com/techwithtim 🔊 Podcast: https://anchor.fm/tech-with-tim 💵 One-Time Donations: https://www.paypal.com/donate/?token=... 💰 Patreon: https://www.patreon.com/techwithtim ◾◾◾◾◾◾ ⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡ Tags: - Tech With Tim - JavaScript for Beginners - JavaScript String Methods - Strings JavaScript - String Methods JavaScript #JavaScript #JS
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 0 of 60

← Previous Next →
1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
3 Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
9 Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

This tutorial teaches beginners how to use JavaScript string methods to manipulate and validate user input, covering topics such as concatenation, trimming, and string length. By following the steps and using the provided code, viewers can learn how to effectively parse and clean user input. The tutorial is practical and hands-on, with a focus on building skills in JavaScript string manipulation.

Key Takeaways
  1. Get user input using document.getElementById().value
  2. Use string methods to modify user input (toUpperCase(), toLowerCase(), startsWith(), endsWith())
  3. Use the startsWith method to check if a string starts with a certain character
  4. Use the endsWith method to check if a string ends with a certain character
  5. Use the trim method to remove any leading or trailing white spaces from a string
  6. Use concatenation to add strings together
  7. Use trimming to remove unnecessary characters from a string
💡 The tutorial highlights the importance of input validation and string manipulation in JavaScript, demonstrating how to use various string methods to parse and clean user input.

Related AI Lessons

Claude AI vs ChatGPT: Which One Is Actually Better in 2026?
Compare Claude AI and ChatGPT based on real-world usage and benchmarking to determine which one is better in 2026
Medium · AI
Claude AI vs ChatGPT: Which One Is Actually Better in 2026?
Compare Claude AI and ChatGPT to determine which AI model is better for your needs in 2026
Medium · Programming
IntelliBooks: Classic RAG vs Graph RAG vs Agentic RAG – Choosing the Right AI Retrieval Architecture for Enterprise AI
Learn to choose the right AI retrieval architecture for enterprise AI between Classic RAG, Graph RAG, and Agentic RAG
Dev.to AI
Fluid, natural voice translation with Gemini 3.5 Live Translate
Learn about Gemini 3.5 Live Translate, a new voice translation technology that enables fluid and natural conversations across languages
Dev.to AI
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →