Цифровой садик - приветственная

Цифровой садик - приветственная | Полный список всего, что тут есть | RSS | Подписаться через follow.it

26.07.2024

javascript

Ссылки

w3 туториал примеры

https://www.w3schools.com/js/exercise_js.asp?filename=exercise_js_string_methods1 https://www.w3schools.com/js/js_strings.asp

После забега про разводяшку, который оказался не нужен:

<p id="demo">JavaScript can change the style of an HTML element.</p>

<button type="button" onclick="document.getElementById('demo').style.fontSize='35px'">Click Me!</button>

<p id="demo">JavaScript can change HTML content.</p>

<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click Me!</button>

JavaScript can "display" data in different ways:

  • Writing into an HTML element, using innerHTML.
  • Writing into the HTML output using document.write().
  • Writing into an alert box, using window.alert().
  • Writing into the browser console, using console.log().

Using document.write() after an HTML document is loaded, will delete all existing HTML:

Массив

JavaScript Arrays

JavaScript arrays are written with square brackets.

Array items are separated by commas.

The following code declares (creates) an array called cars, containing three items (car names): Example var cars = ["Saab", "Volvo", "BMW"];

Хеш (Объект)

JavaScript Objects

JavaScript objects are written with curly braces {}.

Object properties are written as name:value pairs, separated by commas. Example var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

typeof - способ узнать, что тут прячется

typeof something

In JavaScript null is "nothing". It is supposed to be something that doesn't exist.

Unfortunately, in JavaScript, the data type of null is an object.

You can consider it a bug in JavaScript that typeof null is an object. It should be null. You can empty an object by setting it to null: Example var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}; person = null; // Now value is null, but type is still an object

You can also empty an object by setting it to undefined: Example var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}; person = undefined; // Now both value and type is undefined

undefined and null are equal in value but different in type: typeof undefined / undefined typeof null / object

null = undefined / false null == undefined / true

A primitive data value is a single simple data value with no additional properties and methods.

The typeof operator can return one of these primitive types:

string number boolean undefined

The typeof operator can return one of two complex types:

function object

The typeof operator returns "object" for objects, arrays, and null.

The typeof operator does not return "object" for functions.

Разное

  • tool to launch modern Javascript scripts
    Bash is great, but when it comes to writing scripts, people usually choose a more convenient programming language. JavaScript is a perfect choice, but standard Node.js library requires additional hassle before using. The `zx` package provides useful wrappers around `child_process`, escapes arguments and gives sensible defaults. Домашняя страница: https://github.com/google/zx - про запас на всяк случай.

Случайное целое число в диапазоне, включая минимальное и максимальное.

  • Math.ceil — округляет все в большую сторону,
  • Math.floor — в меньшую,
  • Math.round — меньше 0.5 — в меньшую, больше 0.5 — в большую.
function getRandomInRange(min, max) {
       return Math.floor(Math.random() * (max - min + 1)) + min;
   }

console.log(getRandomInRange(0, 9))

convert int to string in javascript.

Using toString()

toString(base) function converts a given a number to the string. It takes an optional parameter base which can be used to specify the base in which the number will be represented as a string.

It works for floating point and exponential numbers also.

let num = 15;
num.toString(); //"15"
num.toString(2); //"1111" (binary)
num.toString(8); //"17"   (octa)
num.toString(16); //"f"   (hexa)

num = 15.55;
num.toString(); //"15.55"

num = 15e10;
num.toString(); //"150000000000"

By concatenating with empty string ""

This the most simplest method which can be used to convert a int to string in javascript.

As javascript is loosely typed language when we concatenate a number with string it converts the number to string.

15 + '' // "15";
15.55 + '' // "15.55";
15e10 + '' // "150000000000"

As you can see we can also convert floating point and exponential numbers.


Если у вас есть мысли, комментарии, предложения или отклики по поводу этой страницы или этого цифрового сада в целом, напишите мне сообщение на agnessa@agnessa.pp.ru. Мне ооочень интересно!

Задонатить.


An IndieWeb Webring 🕸💍