DEV Community

Aliyu Adeniji
Aliyu Adeniji

Posted on • Edited on

1 1

Introduction to JavaScript

JavaScript Variables

Variables are data containers which stores values and information we want the computer to remember in subsequent times. Variables can be changed by simply changing the values of an existing variable to a new one.
Variables are the memory of JavaScript, lets create some variables
var myName="Aliyu" this will save into JavaScript's memory as my name, so next time I try to recall the variable in a function, it'll bring Aliyu as its value.

JavaScript Strings

Stings in JavaScript are values that are enclosed in quotation marks, there are a lot of operations you can do with strings which include printing a value which can be a combination of multiple strings. One of the things you can do with strings is calculating the strings' length and retrieving the number of characters in a string. This can be with in the following syntax;
To count the number of characters in the variable above simply try: myName.length; and teh result will be 5.
Try some code to allow javascript to tell you the number of characters you have written and the number remaining to enter

var tweet = prompt("what is your name");
var tweetcount = tweet.length;
alert("You have written" + tweetcount + "characters, you have" +(200 - tweetcount) + "characters remaining");

Slicing and extracting part of a string

var tweet = prompt("what is your name");
var tweetunder50 = tweet.slice(0,50);
alert(tweetunder50);

you can also shorten your syntax by putting the functions on a single line
alert(prompt("what is your name").slice(0,50));

Changing the characters in a string.

// var name = prompt("What is your name");
// name = name.toUpperCase();
// alert("hello" + " " + name.toUpperCase());
var firstChar = name.slice(0,1);
var remainingchar = name.slice(1,name.length);
// alert(remainingchar);
var lowercaseremainingchar = remainingchar.toLowerCase();
alert(lowercaseremainingchar);

Image of Bright Data

Maintain Seamless Data Collection – No more rotating IPs or server bans.

Avoid detection with our dynamic IP solutions. Perfect for continuous data scraping without interruptions.

Avoid Detection

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay