padStart and padEnd methods | String Object In JavaScript

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • 🎁 Join my channel to get access to perks:
    / @codeexplained
    🧡 Hello All JavaScript Lovers Outhere!
    Today you're going to learn about the String Object In JavaScript.
    This tutorial is a series of videos, in each video we will discuss a method (or more) of the String Object in JavaScript.
    In today's video, you're going to learn about the padStart, and padEnd methods.
    The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.
    The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string.
    🟢🟠 The string.padStart() and string.padEnd().
    🔷 Syntax :
    padStart(targetLength)
    padStart(targetLength, padString)
    padEnd(targetLength)
    padEnd(targetLength, padString)
    🔹targetLength : The length of the resulting string once the current str has been padded. If the value is less than str.length, then str is returned as-is.
    🔹padString : The string to pad the current str with. If padString is too long to stay within the targetLength, it will be truncated from the end. The default value is the unicode "space" character (U+0020).
    🌍 Social Media Links.
    ◾ Facebook : / code.explained.official
    ◾ Twitter : / code_explained
    ◾ Instagram : / code.explained.official
    ◾ GitHub : github.com/Cod...
    💲 Suppport the Channel
    Paypal : paypal.me/Code...
    Buy Me a Coffee: www.buymeacoff...

Комментарии • 8

  • @CodeExplained
    @CodeExplained  7 дней назад

    🚨 Big Announcement! 🚨
    Hey everyone! I've made a big decision for this channel-I've turned off ads on all my videos! That's right, you can now enjoy all my content ad-free! This means I'm earning $0 from ad revenue, but I believe this is the right move to make your viewing experience better.
    If you find my content valuable and want to support my work, there are several ways you can help:
    Like & Share: Simply liking the video and sharing it with friends helps a lot!
    Subscribe & Hit the Bell: Stay updated and never miss a new video.
    RUclips Thanks: Use the "Thanks" button below to send a one-time donation.
    Join the Channel Community: Get exclusive perks and behind-the-scenes content.
    Buy Me a Coffee: buymeacoffee.com/CodeExplained
    PayPal Donation: www.paypal.com/paypalme/CodeExplained
    Every little bit counts and goes directly to creating more high-quality content for you all. Thank you so much for your continued support!
    Let’s keep growing and learning together! 🌟

  • @user-bt2pt7vf7i
    @user-bt2pt7vf7i 4 месяца назад

    very clear

  • @alirezajabbari1263
    @alirezajabbari1263 6 месяцев назад

    Thank you so much! I didn't understand it on w3school!

  • @hosseinpanahy5358
    @hosseinpanahy5358 Год назад +1

    Incredible

  • @juanCOD756
    @juanCOD756 Год назад +1

    thank you, you help me now!!

  • @stephen1569
    @stephen1569 Год назад

    I can't think of a case but, hypothetically, if one's life actually depended on what padding was output, it may not be so good that JS automatically drops the digit 8, as in
    'abc'.padStart(10, '12345678') // abc1234567
    This seems to circumvent the intent of the programmer and seems to be just a shortcut for the convenience of JS. It might be better to throw an error like "RangeError" so the programmer can try to think of a better solution, imho.
    Similarly for the last example when JS just "willy nilly" decides to not add padding instead of throwing an error.

  • @BFGBFW-ABC
    @BFGBFW-ABC Год назад