Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Merkkijonojen ja Numeroiden Käsittely | Osio
Javascriptin Perusteet

bookMerkkijonojen ja Numeroiden Käsittely

Pyyhkäise näyttääksesi valikon

Strings in JavaScript are sequences of characters that you can combine, manipulate, and analyze. You can join strings together using the plus (+) operator, which is called concatenation.

Template literals, enclosed by backticks (`), allow you to insert variables directly into a string using ${}. String methods like length and toUpperCase help you measure and manipulate string values.

1234567891011121314151617
// String concatenation let firstName = "Ada"; let lastName = "Lovelace"; let fullName = firstName + " " + lastName; // "Ada Lovelace" console.log(fullName); // Template literals let age = 30; let greeting = `Hello, my name is ${fullName} and I am ${age} years old.`; console.log(greeting); // Common string methods let shout = fullName.toUpperCase(); // "ADA LOVELACE" console.log(shout); let nameLength = fullName.length; // 12 console.log(nameLength);
copy

Numbers in JavaScript are used for calculations and mathematical operations.

You can perform arithmetic using operators such as +, -, *, and /. The increment (++) and decrement (--) operators add or subtract one from a variable. Sometimes, you need to convert a string to a number for calculations.

JavaScript provides functions like parseInt for whole numbers and parseFloat for decimal numbers to help you convert string values into numbers.

12345678910111213
// Parsing and converting strings to numbers let input = "42"; let parsedInt = parseInt(input); // 42 (number) console.log(parsedInt); let price = "19.99"; let parsedFloat = parseFloat(price); // 19.99 (number) console.log(parsedFloat); // Converting numbers back to strings let num = 100; let numAsString = num.toString(); // "100" console.log(numAsString);
copy
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 5

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Osio 1. Luku 5
some-alt