JavaScript Things To know

gibrish coding
Photo by Markus Spiske on Unsplash

JavaScript String:

Do you know of any programming language that doesn’t use string? Strings are used to show data that are in text form. But sometimes just showing won’t do the work. Let’s start with basics.

const name = "Your Name Here!";
const firstName= str.split(' ');
//output is the first string assigned in name const
const you = 'Love';
const lovedPerson = 'Lovely';
console.log(you.concat('& ', lovedPerson));
//output: "Love & Lovely"
const food = 'i want to have chinese today';console.log(food.toLocaleUpperCase('en-US'));

JavaScript Numbers

Number’s can be tricky not only in JavaScript but everywhere if you’re afraid of it. Now, in JavaScript, there are methods that we certainly need someday. Let’s look at some methods.

let num = 789.123

num.toFixed() // Returns '789': note rounding, no fractional part
num.toFixed(1) // Returns '789.1': note rounding
num.toFixed(6) // Returns '789.123000': note added zeros
console.log(Math.ceil(.85));   // closest to the number 1
// output: 1
console.log(Math.ceil(8)); // rounded already
// expected output: 8
console.log(Math.ceil(8.006)); // rounds it up to 9
// expected output: 9
console.log(Math.ceil(-3.004)); // rounds it up to -3
// expected output: -3
console.log(Math.max(21, 33, 12));
// expected output: 33
console.log(Math.max(-21, -33, -12));
// expected output: -12
const array1 = [21, 33, 12];console.log(Math.max(...array1));
// expected output: 33

JavaScript Arrays

The JavaScript Array class is a global object used in the construction of arrays. You’ve to master some of the array methods if you want to be a good JavaScript developer. Now, let’s declare a basic array in javascript:

let planet = ['Earth', 'Jupiter']

// 2
const planet= ['earth', 'neptune', 'saturn', 'jupitar', 'mars'];const pla = planet.filter(word => planet.length < 4);console.log(pla);
// expected output: Array ["mars"]
const cars = ['toyota', 'bmw', 'landrover', 'hyundai', 'tata'];console.log(cars.pop());
// expected output: "tata"
// expected output: Array ["toyota", "bmw", "landrover", "hyundai"]
// expected output: Array ["toyota", "landrover", "hyundai"]
const cloth = ['shirt', 'pant', 't-shirt'];console.log(cloth);
// expected output: Array ["shirt", "pant", "t-shirt"]
cloth.push('coat', 'tie');
// expected output: Array ["shirt", "pant", "t-shirt", "coat", "tie"];



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store